De-duplicate addresses before returning email subscribers

master
abnercoimbre 2024-10-18 15:10:16 -07:00
parent 19508f38e8
commit e6aeb0158a
1 changed files with 9 additions and 3 deletions

12
main.go
View File

@ -115,15 +115,21 @@ func retrieveSubscribers(cfg *Config) ([]string, error) {
return nil, errors.New("response format error: 'emails' field not found")
}
/* Convert emails to []string */
/* De-duplicate emails using a map */
/* *** */
var subscribers []string
emailMap := make(map[string]bool)
for _, email := range emails {
if emailStr, ok := email.(string); ok {
subscribers = append(subscribers, emailStr)
emailMap[emailStr] = true
}
}
/* Convert the map keys back to a slice */
var subscribers []string
for email := range emailMap {
subscribers = append(subscribers, email)
}
return subscribers, nil
}