fix nil pointer

This commit is contained in:
Ulric Qin 2022-03-22 15:18:45 +08:00
parent 30365a2256
commit 9ccdd6c3e7
1 changed files with 10 additions and 2 deletions

View File

@ -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))