weather-cli/cmd/client/main.go

65 lines
1.2 KiB
Go
Raw Normal View History

package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"sync"
)
2022-07-07 23:43:16 -04:00
type config struct {
Units string `json:"units"`
Location string `json:"loc"`
Longitude string `json:"lat"`
Latitude string `json:"lon"`
}
func main() {
2022-07-07 23:43:16 -04:00
cfg := config{
Units: "F",
}
var option string
var wg sync.WaitGroup
fmt.Println("\n==============================================")
fmt.Println("| Welcome to the OpenWeatherMap-gRPC Client! |")
2022-07-07 23:43:16 -04:00
fmt.Println("==============================================")
for option != "0" {
fmt.Print("\nMain Menu\n---------\n\n")
2022-07-07 23:43:16 -04:00
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 {
2022-07-07 23:43:16 -04:00
log.Println(err)
}
option = strings.TrimSuffix(input, "\n")
2022-07-07 23:43:16 -04:00
if option == "1" || option == "" {
wg.Add(1)
go getLocation(&wg, &cfg)
wg.Wait()
} else if option == "2" {
wg.Add(1)
2022-07-07 23:43:16 -04:00
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")
}
}
}