Skip to content

Commit

Permalink
Removing duplicate targets.
Browse files Browse the repository at this point in the history
  • Loading branch information
freddielunchbird committed Jun 22, 2023
1 parent f26588b commit d7b1a32
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmon_sd.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,26 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
}

}

temp.Target = removeDuplicateStr(temp.Target)
clusterTarget = append(clusterTarget, temp)
i++
}

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(clusterTarget)
}

func removeDuplicateStr(strSlice []string) []string {
allKeys := make(map[string]bool)
list := []string{}
for _, item := range strSlice {
if _, value := allKeys[item]; !value {
allKeys[item] = true
list = append(list, item)
}
}
return list
}

var port int
Expand Down

0 comments on commit d7b1a32

Please sign in to comment.