handle zip of lat.long
This commit is contained in:
parent
4b0ef3e33a
commit
db43d9e80a
1 changed files with 12 additions and 1 deletions
13
main.go
13
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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue