De-duplicate addresses before returning email subscribers
parent
19508f38e8
commit
e6aeb0158a
12
main.go
12
main.go
|
@ -115,15 +115,21 @@ func retrieveSubscribers(cfg *Config) ([]string, error) {
|
||||||
return nil, errors.New("response format error: 'emails' field not found")
|
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 {
|
for _, email := range emails {
|
||||||
if emailStr, ok := email.(string); ok {
|
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
|
return subscribers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue