server: Prevent nil map access crash
continuous-integration/drone/push Build is failing Details

master
Luther Wen Xu 2020-04-24 15:33:57 +07:00
parent 62e4645b63
commit 3bb5187e39
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
1 changed files with 4 additions and 1 deletions

@ -16,7 +16,7 @@ type stat struct {
Summary check.Result `json:"summary"`
}
var dayAggregation map[string]map[time.Time]stat
var dayAggregation = make(map[string]map[time.Time]stat)
func convertToResult(successCount, totalCount int) check.Result {
if successCount >= totalCount*99/100 {
@ -29,6 +29,9 @@ func convertToResult(successCount, totalCount int) check.Result {
}
func getDay(serviceName string, day time.Time) stat {
if _, ok := dayAggregation[serviceName]; !ok {
dayAggregation[serviceName] = make(map[time.Time]stat)
}
if cached, ok := dayAggregation[serviceName][day]; ok {
return cached
}