summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsiddharth ravikumar <s@ricketyspace.net>2022-06-18 03:27:09 -0400
committersiddharth ravikumar <s@ricketyspace.net>2022-06-18 03:27:09 -0400
commite605d52c2288b53cd78c7db7d290c386161bbf17 (patch)
treef2b8d4192986fc6162b8be68a3e9c6f33df5b2e7
parentb2cfb74403b0052b51477a0200c77f8b5f5270ed (diff)
weather: update `NewWeather`
Add alerts.
-rw-r--r--weather/weather.go22
1 files changed, 22 insertions, 0 deletions
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
}