summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2018-03-22 16:39:39 +0000
committerNick White <git@njw.name>2018-03-22 16:39:39 +0000
commit70d7d624153f94e2e3221ae30df8c33bb60ecbed (patch)
treefe98c60776bbc896da7cf98f9f1861cbed0f89ae
parent12e6824b8f0e6f6bb1ea921aa26a2d485fc9dcd9 (diff)
downloadweather-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.go6
1 files 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 {