From 28d101636212e8e539512916c4587ea8bf657ddb Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 20 Sep 2015 16:48:35 +0200 Subject: Add weather --- metar.go | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 metar.go (limited to 'metar.go') diff --git a/metar.go b/metar.go deleted file mode 100644 index c19fe6d..0000000 --- a/metar.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "errors" - "io/ioutil" - "net/http" - "strings" -) - -const ( - noaa = `http://weather.noaa.gov/pub/data/observations/metar/` - noaaDecoded = noaa + `decoded/` - noaaStations = noaa + `stations/` -) - -var notFound = errors.New("not found") - -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 - } - defer resp.Body.Close() - if resp.StatusCode == http.StatusNotFound { - return nil, notFound - } - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, err - } - 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