weather-cli/cmd/client/main.go

64 lines
1.2 KiB
Go

package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"sync"
)
type config struct {
Units string `json:"units"`
Location string `json:"loc"`
Longitude string `json:"lat"`
Latitude string `json:"lon"`
}
func main() {
cfg := config{
Units: "F",
}
var option string
var wg sync.WaitGroup
fmt.Println("\n==============================================")
fmt.Println("| Welcome to the OpenWeatherMap-gRPC Client! |")
fmt.Println("==============================================")
for option != "0" {
fmt.Print("\nMain Menu\n---------\n\n")
fmt.Println("1. Today's forecast (use current location, default)")
fmt.Println("2. Advanced options")
fmt.Print("0. Exit\n\n")
reader := bufio.NewReader(os.Stdin)
input, err := reader.ReadString('\n')
if err != nil {
log.Println(err)
}
option = strings.TrimSuffix(input, "\n")
if option == "1" || option == "" {
wg.Add(1)
go getLocation(&wg, &cfg)
wg.Wait()
} else if option == "2" {
wg.Add(1)
go advancedMenu(&wg, &cfg)
wg.Wait()
} else if option == "0" {
return
} else {
fmt.Print("\nOops! An error occurred, please choose a valid option.\n\n")
}
}
}