summaryrefslogtreecommitdiffstats
path: root/nws
diff options
context:
space:
mode:
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 6f75979..567d1a8 100644
--- a/nws/nws.go
+++ b/nws/nws.go
@@ -74,30 +74,14 @@ func (e Error) Error() string {
// TODO: return Error instead of error
func Points(lat, lng float32) (*Point, error) {
url := fmt.Sprintf("https://api.weather.gov/points/%.4f,%.4f", lat, lng)
- resp, err := client.Get(url)
- if err != nil {
- return nil, fmt.Errorf("points: http get: %v", err)
- }
-
- // Parse response body.
- body, err := io.ReadAll(resp.Body)
- if err != nil {
- return nil, fmt.Errorf("points: 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("points: json: %v", err)
- }
- return nil, fmt.Errorf("points: %v", perr)
+ body, nwsErr := get(url)
+ if nwsErr != nil {
+ return nil, fmt.Errorf("points: %v", nwsErr)
}
// Unmarshal.
point := new(Point)
- err = json.Unmarshal(body, point)
+ err := json.Unmarshal(body, point)
if err != nil {
return nil, fmt.Errorf("points: decode: %v", err)
}