go-openweather/cmd/openweatherclient/main.go
2019-12-09 15:14:29 +01:00

30 lines
642 B
Go

package main
import (
"flag"
"fmt"
"github.com/EricNeid/go-openweather"
)
func main() {
keyPtr := flag.String("key", "", "Supply valid api key, see https://home.openweathermap.org/users/sign_up for details.")
cityPtr := flag.String("city", "", "City to look up")
flag.Parse()
if len(*keyPtr) == 0 || len(*cityPtr) == 0 {
fmt.Println("Usage: simpleclient.exe -key <api-key> -city <city-to-query>")
return
}
query := openweather.NewQueryForCity(*keyPtr, *cityPtr, "metric")
weather, err := query.WeatherRaw()
if err != nil {
fmt.Println("Error while retrieving data: " + err.Error())
return
}
fmt.Println(weather)
}