summaryrefslogtreecommitdiffstats
path: root/nws
diff options
context:
space:
mode:
authorsiddharth ravikumar <s@ricketyspace.net>2022-06-05 14:53:18 -0400
committersiddharth ravikumar <s@ricketyspace.net>2022-06-05 14:53:18 -0400
commitded5355e88de5adef17b3509630648b24f6cf4ac (patch)
tree80b677fbc46e45a25333c2aab26b5ab98f3f7416 /nws
parent2081e91caefda0c5dd92069401eee4ffc2e075dd (diff)
nws: update GetForecast
Use `nws.get` for hitting the NWS forecast endpoint.
Diffstat (limited to 'nws')
-rw-r--r--nws/nws.go24
1 files changed, 4 insertions, 20 deletions
diff --git a/nws/nws.go b/nws/nws.go
index 2fc5662..3a7081e 100644
--- a/nws/nws.go
+++ b/nws/nws.go
@@ -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)
}