summaryrefslogtreecommitdiffstats
path: root/weather
diff options
context:
space:
mode:
authorsiddharth ravikumar <s@ricketyspace.net>2022-06-18 06:19:41 -0400
committersiddharth ravikumar <s@ricketyspace.net>2022-06-18 06:19:41 -0400
commit43365bd5d8b55e5f490ee96d5b631521735a3ed8 (patch)
treef70422d29b1b7efa5a7634a7ec905c39c07512ea /weather
parent9b14bf5641ba8ecee34d9b266864ae198550af5c (diff)
weather: update `NewWeather`
Add handling to skip duplicate alerts.
Diffstat (limited to 'weather')
-rw-r--r--weather/weather.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/weather/weather.go b/weather/weather.go
index e001255..7b7161a 100644
--- a/weather/weather.go
+++ b/weather/weather.go
@@ -121,7 +121,11 @@ func NewWeather(lat, lng float32) (*Weather, error, int) {
// Add alerts if they exist.
if len(fBundle.Alerts.Features) > 0 {
w.Alerts = make([]Alert, 0)
+ am := make(map[string]bool, 0) // Alerts map.
for _, f := range fBundle.Alerts.Features {
+ if _, ok := am[f.Id]; ok {
+ continue // Duplicate; skip.
+ }
a := Alert{
Event: f.Properties.Event,
Severity: f.Properties.Severity,
@@ -129,6 +133,7 @@ func NewWeather(lat, lng float32) (*Weather, error, int) {
Instruction: strings.Split(f.Properties.Instruction, "\n\n"),
}
w.Alerts = append(w.Alerts, a)
+ am[f.Id] = true
}
}
return w, nil, 200