diff --git a/main.go b/main.go index 4abaff0..aa52255 100644 --- a/main.go +++ b/main.go @@ -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) }