diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-04-08 03:01:38 +0200 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-04-09 03:37:21 +0200 |
commit | 309f63f5b10dbf492852d4b1c2638b48c6863207 (patch) | |
tree | 236f4a70f750500143a6782888267a4263d22360 | |
parent | 4ea92c8a0a775aea4a57ad87a7a767ee7071132c (diff) |
forecast.io: check location == lat,lon
-rw-r--r-- | backends/forecast.io.go | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/backends/forecast.io.go b/backends/forecast.io.go index 45f9e0d..ed4c8e9 100644 --- a/backends/forecast.io.go +++ b/backends/forecast.io.go @@ -1,6 +1,7 @@ package backends import ( + "regexp" "encoding/json" "flag" "fmt" @@ -206,6 +207,9 @@ func (c *forecastConfig) Fetch(location string, numdays int) iface.Data { if len(c.apiKey) == 0 { log.Fatal("No forecast.io API key specified.\nYou have to register for one at https://developer.forecast.io/register") } + if matched, err := regexp.MatchString(`^-?[0-9]*(\.[0-9]+)?,-?[0-9]*(\.[0-9]+)?$`, location); !matched || err != nil { + log.Fatalf("Error: The forecast.io backend only supports latitude,longitude pairs as location.\nTry `40.748,-73.985` instead of `%s` to get weather for New York", location) + } c.tz = time.Local |