diff options
author | siddharth ravikumar <s@ricketyspace.net> | 2022-06-05 14:53:18 -0400 |
---|---|---|
committer | siddharth ravikumar <s@ricketyspace.net> | 2022-06-05 14:53:18 -0400 |
commit | ded5355e88de5adef17b3509630648b24f6cf4ac (patch) | |
tree | 80b677fbc46e45a25333c2aab26b5ab98f3f7416 /nws | |
parent | 2081e91caefda0c5dd92069401eee4ffc2e075dd (diff) |
nws: update GetForecast
Use `nws.get` for hitting the NWS forecast endpoint.
Diffstat (limited to 'nws')
-rw-r--r-- | nws/nws.go | 24 |
1 files changed, 4 insertions, 20 deletions
@@ -122,30 +122,14 @@ func GetForecast(point *Point) (*Forecast, error) { } // Get the forecast - resp, err := client.Get(point.Properties.Forecast) - if err != nil { - return nil, fmt.Errorf("forecast: get: %v", err) - } - - // Parse response body. - body, err := io.ReadAll(resp.Body) - if err != nil { - return nil, fmt.Errorf("forecast: body: %v", err) - } - - // Check if the request failed. - if resp.StatusCode != 200 { - perr := new(Error) - err := json.Unmarshal(body, perr) - if err != nil { - return nil, fmt.Errorf("forecast: json: %v", err) - } - return nil, fmt.Errorf("forecast: %v", perr) + body, nwsErr := get(point.Properties.Forecast) + if nwsErr != nil { + return nil, fmt.Errorf("forecast: %v", nwsErr) } // Unmarshal. forecast := new(Forecast) - err = json.Unmarshal(body, forecast) + err := json.Unmarshal(body, forecast) if err != nil { return nil, fmt.Errorf("forecast: decode: %v", err) } |