in walkthroughs/howto-outlier-detection/src/frontend-app/main.go [46:94]
func updateStats(hostUID string, status int) {
counterMutex.Lock()
defer counterMutex.Unlock()
found := false
for i, h := range hostsStats {
if h.HostUID == hostUID {
hostsStats[i].Counter.Total++
if status == http.StatusOK {
hostsStats[i].Counter.StatusOk++
} else {
hostsStats[i].Counter.StatusError++
}
found = true
}
}
if !found {
var newHost hostStatusCounter
if status == http.StatusOK {
newHost = hostStatusCounter{
HostUID: hostUID,
Counter: struct {
StatusOk int
StatusError int
Total int
}{
StatusOk: 1,
StatusError: 0,
Total: 1,
},
}
} else {
newHost = hostStatusCounter{
HostUID: hostUID,
Counter: struct {
StatusOk int
StatusError int
Total int
}{
StatusOk: 0,
StatusError: 1,
Total: 1,
},
}
}
hostsStats = append(hostsStats, newHost)
}
fmt.Println("stats updated: ", hostsStats)
}