summaryrefslogtreecommitdiffstats
path: root/nws
diff options
context:
space:
mode:
authorsiddharth <s@ricketyspace.net>2022-05-15 22:57:14 -0400
committersiddharth <s@ricketyspace.net>2022-05-15 22:57:14 -0400
commitcb8506da1b23d50796bf14a16ffe44781bf36e32 (patch)
tree73d96fc587c51d30bc90a182adf46e02fa0cccbb /nws
parent937d75d2fc150c29d3510656211dae0aac7aa643 (diff)
nws: NWSPoints -> NWSPoint
Also NWSPointsError -> NWSPointError
Diffstat (limited to 'nws')
-rw-r--r--nws/nws.go23
1 files changed, 12 insertions, 11 deletions
diff --git a/nws/nws.go b/nws/nws.go
index 1d6e061..8091842 100644
--- a/nws/nws.go
+++ b/nws/nws.go
@@ -20,23 +20,23 @@ type NWSPointProperties struct {
ForecastHourlyLink string `json:"forecastHourly"`
}
-type NWSPoints struct {
+type NWSPoint struct {
Properties NWSPointProperties
}
-type NWSPointsError struct {
+type NWSPointError struct {
Title string
Type string
Status int
Detail string
}
-func (e NWSPointsError) Error() string {
+func (e NWSPointError) Error() string {
return fmt.Sprintf("%d: %s: %s", e.Status, e.Type, e.Detail)
}
// NWS `/points` endpoint.
-func Points(lat, lng float32) (*NWSPoints, error) {
+func Points(lat, lng float32) (*NWSPoint, error) {
url := fmt.Sprintf("https://api.weather.gov/points/%.4f,%.4f", lat, lng)
resp, err := client.Get(url)
if err != nil {
@@ -51,7 +51,7 @@ func Points(lat, lng float32) (*NWSPoints, error) {
// Check if the request failed.
if resp.StatusCode != 200 {
- perr := new(NWSPointsError)
+ perr := new(NWSPointError)
err := json.Unmarshal(body, perr)
if err != nil {
return nil, fmt.Errorf("points: json: %v", err)
@@ -60,16 +60,17 @@ func Points(lat, lng float32) (*NWSPoints, error) {
}
// Unmarshal.
- points := new(NWSPoints)
- err = json.Unmarshal(body, points)
+ point := new(NWSPoint)
+ err = json.Unmarshal(body, point)
if err != nil {
- return nil, fmt.Errorf("getting points: json decode: %v", err)
+ return nil, fmt.Errorf("points: json decode: %v", err)
}
- if points.Properties.ForecastLink == "" {
+ if point.Properties.ForecastLink == "" {
return nil, fmt.Errorf("points: json: %v", err)
}
- if points.Properties.ForecastHourlyLink == "" {
+ if point.Properties.ForecastHourlyLink == "" {
return nil, fmt.Errorf("points: json: %v", err)
}
- return points, nil
+ return point, nil
}
+