I have my code working but I am sure that it is not optimal.
I am building a Map[string]string that contains my alarm names as keys and instanceids as values. I have an array that has just instanceids in it. I need to remove any keys from the map that have values that match the instanceids in the array. Then return a []string of alarm names. My code is working but thought that it would be good to see if I did this remotely correct. The []string in the return is optional I could probably just use the map.
Thanks for the input.
func CheckAlarms(alarmMap map[string]string, instances []string) (result []string) {
var AlarmList []string
for _, inst := range instances{
for k, v := range alarmMap{
if v == inst{
log.Printf("**** Match Found add alarm to delete list %s
", k)
delete(alarmMap, k)
}
}
}
for k, v := range alarmMap{
var inst []string
AlarmList = append(AlarmList, k)
inst = append(inst, v)
}
log.Printf("end of function list length %d", len(AlarmList))
return AlarmList
}