From c3b81b0f04f35c8be63b8daff04829382050644a Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 9 Jul 2015 18:35:04 +0200 Subject: Update weather --- metar.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'metar.go') diff --git a/metar.go b/metar.go index 581a158..c19fe6d 100644 --- a/metar.go +++ b/metar.go @@ -1,10 +1,10 @@ package main import ( + "errors" "io/ioutil" "net/http" "strings" - "errors" ) const ( @@ -15,8 +15,8 @@ const ( var notFound = errors.New("not found") -func FetchMetar(s string) ([]string, error) { - loc := noaaDecoded + strings.ToUpper(s[:4]) + ".TXT" +func fetchMetar(base, station string) ([]string, error) { + loc := base + strings.ToUpper(station[:4]) + ".TXT" resp, err := http.Get(loc) if err != nil { return nil, err @@ -31,3 +31,11 @@ func FetchMetar(s string) ([]string, error) { } return strings.Split(strings.TrimSpace(string(body)), "\n"), nil } + +func MetarDecoded(s string) ([]string, error) { + return fetchMetar(noaaDecoded, s) +} + +func MetarStation(s string) ([]string, error) { + return fetchMetar(noaaStations, s) +} -- cgit v1.2.3