Don't allow duplicate values in NodeAddresses

This commit is contained in:
Justin Santa Barbara
2015-03-05 16:40:28 -08:00
parent e8ee20afff
commit bf031fb082
4 changed files with 21 additions and 5 deletions

View File

@@ -1405,3 +1405,19 @@ const (
PortHeader = "port"
)
// Appends the NodeAddresses to the passed-by-pointer slice, only if they do not already exist
func AddToNodeAddresses(addresses *[]NodeAddress, addAddresses ...NodeAddress) {
for _, add := range addAddresses {
exists := false
for _, existing := range *addresses {
if existing.Address == add.Address && existing.Type == add.Type {
exists = true
break
}
}
if !exists {
*addresses = append(*addresses, add)
}
}
}