From 3bb5187e390ee8bdce0dcfe4743c6b3a9eb900c8 Mon Sep 17 00:00:00 2001 From: Luther Wen Xu Date: Fri, 24 Apr 2020 15:33:57 +0800 Subject: [PATCH] server: Prevent nil map access crash --- server/cache.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/cache.go b/server/cache.go index bb0c3d1..8bc4246 100644 --- a/server/cache.go +++ b/server/cache.go @@ -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 }