From a7fcc6f8f7384ff8dfa029d5164805cb45b9de14 Mon Sep 17 00:00:00 2001 From: Daniele Sluijters Date: Mon, 27 Jun 2022 19:45:55 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Ensure=20the=20station=20is=20activ?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the station is inactive we should error out. When a station is inactive it's not delivering data. --- main.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index e25220e..581098e 100644 --- a/main.go +++ b/main.go @@ -221,15 +221,20 @@ func retrieve(ctx context.Context, client *http.Client, body []byte) (data, erro return data{}, fmt.Errorf("station with ID: %s does not exist", *stationID) } + station := wr.Response.Result[0].WeatherStation[0] + if station.Active != nil && !*station.Active { + return data{}, fmt.Errorf("station with ID: %s is not active", *stationID) + } + precip := 0.0 - if data := wr.Response.Result[0].WeatherStation[0].Measurement.Precipitation.Amount; data != nil { + if data := station.Measurement.Precipitation.Amount; data != nil { precip = *data } return data{ - name: *wr.Response.Result[0].WeatherStation[0].Name, - tempC: *wr.Response.Result[0].WeatherStation[0].Measurement.Air.Temperature, - rhPct: *wr.Response.Result[0].WeatherStation[0].Measurement.Air.RelativeHumidity, + name: *station.Name, + tempC: *station.Measurement.Air.Temperature, + rhPct: *station.Measurement.Air.RelativeHumidity, precip: precip, }, nil }