diff options
author | siddharth ravikumar <s@ricketyspace.net> | 2022-06-05 15:00:29 -0400 |
---|---|---|
committer | siddharth ravikumar <s@ricketyspace.net> | 2022-06-05 15:00:29 -0400 |
commit | ed02eba421b6cd200e017c9efdaaf0d20038f6b0 (patch) | |
tree | 4faafd238d6613e5cafb63c2e01d935afe74cfbf /nws | |
parent | 52278d2721a19482544026eb5dda6f7cf906a9e8 (diff) |
nws: update `Points`
Use `nws.get` for hitting the NWS points endpoint.
Diffstat (limited to 'nws')
-rw-r--r-- | nws/nws.go | 24 |
1 files changed, 4 insertions, 20 deletions
@@ -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) } |