我正在尝试将项目附加到我拥有的这个结构中:
type AuditSource struct {
Source map[string][]Pgm `json:"Source"`
}
type Pgm struct {
ID uint `json:"id,omitempty"`
SourceIP Inet `json:"sourceip,omitempty"`
MulticastPort int `json:"multicastport,omitempty"`
}
func NewAuditSource(lid string) (a *AuditSource) {
a = &AuditSource{
Id: make(map[string]uint64),
Source: make(map[string][]Pgm),
}
return
}
func (as *AuditSource) AuditSourceDifferences(a, b int) bool{
if a != b {
as.Source["Primary"][0].MulticastPort =a //ERRORS out every time
as.Source["Primary"][1].MulticastPort =b
}
return true
}
知道为什么每次尝试向其中添加内容时我的 struct map[string][]Pgm 都会出错吗?我可能需要初始化 []Pgm 吗?