From db43d9e80aafc11df985493797fedc1bc5da666f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=C3=A1n=20C=20McCord?= Date: Mon, 7 Nov 2022 15:12:40 -0500 Subject: [PATCH] handle zip of lat.long --- main.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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) }