我必须让结构说 struct1 和 struct2,struct2 包含一个带有 struct1 的映射,struct1 也包含一个映射,我想更改 struct1 中存在的映射。
这是抛出运行时错误: 恐慌:运行时错误:无效内存地址或零指针取消引用
type FailureData struct {
failuresInCommits map[string][]string
}
type DetectionResults struct {
Failures map[git_repo.FilePath]*FailureData
//Have other things
}
func (r *DetectionResults) Fail(filePath git_repo.FilePath, message
string, commits []string) {
ok := r.Failures[filePath].failuresInCommits //error occurs here
if r.Failures[filePath].failuresInCommits == nil {
r.Failures[filePath].failuresInCommits = make(map[string][]string)
}
if len(ok) == 0 {
r.Failures[filePath].failuresInCommits[message] = commits
} else {
r.Failures[filePath].failuresInCommits[message] =
append(r.Failures[filePath].failuresInCommits[message],
commits...)
}
}
守着一只汪
相关分类