From 70d7d624153f94e2e3221ae30df8c33bb60ecbed Mon Sep 17 00:00:00 2001 From: Nick White Date: Thu, 22 Mar 2018 16:39:39 +0000 Subject: Use default net/http client, and check HTTP response code Was using client/transport mistakenly. Don't continue if HTTP transfer failed. --- weather.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/weather.go b/weather.go index f14ec38..4eb5c13 100644 --- a/weather.go +++ b/weather.go @@ -73,12 +73,14 @@ func main() { id = defid } - client := &http.Client{Transport: &http.Transport{}} - resp, err := client.Get("https://www.metoffice.gov.uk/public/data/PWSCache/BestForecast/Forecast/" + id + ".json?concise=true") + resp, err := http.Get("https://www.metoffice.gov.uk/public/data/PWSCache/BestForecast/Forecast/" + id + ".json?concise=true") if err != nil { log.Fatal(err) } defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + log.Fatalf("HTTP status code: %d\n", resp.StatusCode) + } b, err := ioutil.ReadAll(resp.Body) err = json.Unmarshal(b, &r) if err != nil { -- cgit v1.2.3