for _, v := range resultObjects {
sd, exist := m[v.Endpoint]
if !exist {
sd := new(SavedData) // sd = new(SavedData)
sd.Ip = v.Endpoint
sd.StartTime = time.Unix(start, 0)
sd.EndTime = time.Unix(end, 0)
m[v.Endpoint] = sd
}
...
...
...
sd.CpuMax = float64(max)
sd.CpuMin = min
m[v.Endpoint] = sd
}
跑这段代码会出现这个问题:
panic: runtime error: invalid memory address or nil pointer dereference
因为忽略了作用域