diff --git a/cmd/client/main.go b/cmd/client/main.go index b79556f..5b32529 100644 --- a/cmd/client/main.go +++ b/cmd/client/main.go @@ -46,34 +46,15 @@ type application struct { Version string } -func printWeather(app *application) { - - var unitStr string - if app.Config.Units == "imperial" { - unitStr = "Farhenheit/mph" - } else { - unitStr = "Celsius/kph" - } - - fmt.Println("\nNote! A value of 0 or 0.00 indicates the data is not available at this time.") - fmt.Printf("Units: %s (%s)\n\n", app.Config.Units, unitStr) - fmt.Printf("Current temperature: %.2f\n", app.Forecast.Main.Temp) - fmt.Printf("Feels like: %.2f\n", app.Forecast.Main.FeelsLike) - fmt.Printf("High: %.2f\n", app.Forecast.Main.HighTemp) - fmt.Printf("Low: %.2f\n", app.Forecast.Main.LowTemp) - fmt.Printf("Pressure (hPa): %d\n", app.Forecast.Main.Pressure) - fmt.Printf("Humidty (%%): %d\n", app.Forecast.Main.Humidity) - fmt.Printf("Wind speed: %.2f\n", app.Forecast.Wind.Speed) - fmt.Printf("Gust: %.2f\n", app.Forecast.Wind.Gust) -} - func main() { + // Load .env err := godotenv.Load() if err != nil { log.Fatalln(err) } + // Read API_KEY from .env and create app cfg := config{ Units: "imperial", ApiKey: os.Getenv("API_KEY"), @@ -87,8 +68,7 @@ func main() { Version: version, } - var option string - + // Display main menu fmt.Println("\n=====================================================") fmt.Printf("| Welcome to the OpenWeatherMap-gRPC Client! v%s |\n", app.Version) fmt.Println("=====================================================") @@ -98,22 +78,23 @@ func main() { fmt.Println(" - Advanced option: Enter exact location for anywhere in the world") fmt.Println(" - Advanced option: Change back and forth between imperial and metric units of measurement") + var option string + // Menu loop 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 (Change units, precise location, etc.)") fmt.Print("0. Exit\n\n") + // Read user input reader := bufio.NewReader(os.Stdin) input, err := reader.ReadString('\n') if err != nil { log.Println(err) } - option = strings.TrimSuffix(input, "\n") + // Check user input if option == "1" || option == "" { getLocation(&app) getCurrent(&app)