summaryrefslogtreecommitdiffstats
path: root/nws
diff options
context:
space:
mode:
authorsiddharth ravikumar <s@ricketyspace.net>2022-06-05 14:57:52 -0400
committersiddharth ravikumar <s@ricketyspace.net>2022-06-05 14:57:52 -0400
commit52278d2721a19482544026eb5dda6f7cf906a9e8 (patch)
tree3fa4aa157260355e1836b61ccdf97985957e1ac9 /nws
parentded5355e88de5adef17b3509630648b24f6cf4ac (diff)
nws: update GetForecastHourly
Use `nws.get` for hitting the NWS forecast hourly endpoint.
Diffstat (limited to 'nws')
-rw-r--r--nws/nws.go26
1 files changed, 5 insertions, 21 deletions
diff --git a/nws/nws.go b/nws/nws.go
index 3a7081e..6f75979 100644
--- a/nws/nws.go
+++ b/nws/nws.go
@@ -150,31 +150,15 @@ func GetForecastHourly(point *Point) (*Forecast, error) {
return nil, fmt.Errorf("forecast hourly: link empty")
}
- // Get the forecast
- resp, err := client.Get(point.Properties.ForecastHourly)
- if err != nil {
- return nil, fmt.Errorf("forecast hourly: get: %v", err)
- }
-
- // Parse response body.
- body, err := io.ReadAll(resp.Body)
- if err != nil {
- return nil, fmt.Errorf("forecast hourly: 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 hourly: json: %v", err)
- }
- return nil, fmt.Errorf("forecast: %v", perr)
+ // Get the hourly forecast.
+ body, nwsErr := get(point.Properties.ForecastHourly)
+ if nwsErr != nil {
+ return nil, fmt.Errorf("forecast hourly: %v", nwsErr)
}
// Unmarshal.
forecast := new(Forecast)
- err = json.Unmarshal(body, forecast)
+ err := json.Unmarshal(body, forecast)
if err != nil {
return nil, fmt.Errorf("forecast hourly: decode: %v", err)
}