handle zip of lat.long

This commit is contained in:
Seán C McCord 2022-11-07 15:12:40 -05:00
parent 4b0ef3e33a
commit db43d9e80a
Signed by: scm
GPG key ID: 8302D5513BFE9618

13
main.go
View file

@ -13,11 +13,15 @@ import (
var apiKey = "91dbd7a9a3ab3f06b9d944d42d76faf8"
var zipCode = 30310
var lat = 0.0
var long = 0.0
var units = "C"
func init() {
//flag.StringVar(&apiKey, "api", "", "API key for openweathermap.com")
flag.IntVar(&zipCode, "zip", 30310, "zip code for weather location")
flag.Float64Var(&lat, "lat", 0.0, "latitude of location")
flag.Float64Var(&long, "long", 0.0, "longitude of location")
}
type output struct {
@ -33,7 +37,14 @@ func main() {
if err != nil {
log.Fatal("failed to create current weather service:", err)
}
if err := c.CurrentByZip(zipCode, "us"); err != nil {
if lat != 0.0 && long != 0.0 {
if err := c.CurrentByCoordinates(&openweathermap.Coordinates{
Latitude: lat,
Longitude: long,
}); err != nil {
log.Fatal("failed to get local weather:", err)
}
} else if err := c.CurrentByZip(zipCode, "us"); err != nil {
log.Fatal("failed to get local weather:", err)
}