From 9ccdd6c3e707d89d936997f4e69a5103affa5d58 Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Tue, 22 Mar 2022 15:18:45 +0800 Subject: [PATCH] fix nil pointer --- src/webapi/router/router_alert_cur_event.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/webapi/router/router_alert_cur_event.go b/src/webapi/router/router_alert_cur_event.go index e486c8aa..03736094 100644 --- a/src/webapi/router/router_alert_cur_event.go +++ b/src/webapi/router/router_alert_cur_event.go @@ -53,8 +53,16 @@ func alertCurEventsCard(c *gin.Context) { cardmap := make(map[string]*AlertCard) for _, event := range list { title := event.GenCardTitle(rules) - cardmap[title].Total++ - cardmap[title].EventIds = append(cardmap[title].EventIds, event.Id) + if _, has := cardmap[title]; has { + cardmap[title].Total++ + cardmap[title].EventIds = append(cardmap[title].EventIds, event.Id) + } else { + cardmap[title] = &AlertCard{ + Total: 1, + EventIds: []int64{event.Id}, + Title: title, + } + } } titles := make([]string, 0, len(cardmap))