这是一个示例,我每次都会分配给 nil 映射中的条目
:
https://play.golang.org/p/LudJs0rVbs
为了演示我想要做什么,这里有一个简单的版本,它会导致对数据库进行 2 次查找(您必须在第 11 行发挥您的想象力): https://play.golang.org/p/YZNFeMHyMs
基本上,我正在尝试这样做:
things := make(map[string]map[string][]Struct)
...
stuff, there := things["first key"]
if !there {
things["first key"] = getAMapOfStringToStructs()
}
doSomethingWith(things["first key"])
我查看了更多 trivial examples of maps-of-maps here但我似乎无法将其映射到我的问题。
最佳答案
您从未在 allEntries
map 上执行过 make
:
allEntries = make(map[string]map[string][]Thing)
关于go - 结构图和 "assignment to entry in nil map"的图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30243581/