From ed02eba421b6cd200e017c9efdaaf0d20038f6b0 Mon Sep 17 00:00:00 2001 From: siddharth ravikumar Date: Sun, 5 Jun 2022 15:00:29 -0400 Subject: nws: update `Points` Use `nws.get` for hitting the NWS points endpoint. --- nws/nws.go | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) (limited to 'nws') 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) } -- cgit v1.2.3