diff options
author | Nick White <git@njw.name> | 2018-03-22 16:39:39 +0000 |
---|---|---|
committer | Nick White <git@njw.name> | 2018-03-22 16:39:39 +0000 |
commit | 70d7d624153f94e2e3221ae30df8c33bb60ecbed (patch) | |
tree | fe98c60776bbc896da7cf98f9f1861cbed0f89ae | |
parent | 12e6824b8f0e6f6bb1ea921aa26a2d485fc9dcd9 (diff) | |
download | weather-70d7d624153f94e2e3221ae30df8c33bb60ecbed.tar.bz2 weather-70d7d624153f94e2e3221ae30df8c33bb60ecbed.zip |
Use default net/http client, and check HTTP response code
Was using client/transport mistakenly.
Don't continue if HTTP transfer failed.
-rw-r--r-- | weather.go | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -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 { |