From e605d52c2288b53cd78c7db7d290c386161bbf17 Mon Sep 17 00:00:00 2001 From: siddharth ravikumar Date: Sat, 18 Jun 2022 03:27:09 -0400 Subject: weather: update `NewWeather` Add alerts. --- weather/weather.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/weather/weather.go b/weather/weather.go index 2eb2bf7..c3f48a3 100644 --- a/weather/weather.go +++ b/weather/weather.go @@ -21,6 +21,7 @@ type Weather struct { Q2HTimeline WeatherTimeline // Q2H forecast of the next 12 hours. BiDailyTimeline WeatherTimeline // BiDaily forecast for the next 3 days. SearchEnabled bool + Alerts []Alert } type WeatherNow struct { @@ -43,6 +44,13 @@ type WeatherTimeline struct { Periods []WeatherPeriod } +type Alert struct { + Event string + Severity string + Description string + Instruction string +} + func NewWeather(lat, lng float32) (*Weather, error, int) { fBundle, nwsErr := nws.GetForecastBundle(lat, lng) if nwsErr != nil { @@ -110,5 +118,19 @@ func NewWeather(lat, lng float32) (*Weather, error, int) { } w.SearchEnabled = photon.Enabled() + // Add alerts if they exist. + if len(fBundle.Alerts.Features) > 0 { + w.Alerts = make([]Alert, 0) + for _, f := range fBundle.Alerts.Features { + a := Alert{ + Event: f.Properties.Event, + Severity: f.Properties.Severity, + Description: f.Properties.Description, + Instruction: f.Properties.Instruction, + } + w.Alerts = append(w.Alerts, a) + } + } + return w, nil, 200 } -- cgit v1.2.3