【发布时间】:2021-05-18 13:44:25
【问题描述】:
我有以下结构:
type InstructionSet struct {
Inst map[string]interface{}
}
在Inst 地图中,我想放一些类似的东西
Inst["cmd"] = "dir"
Inst["timeout"] = 10
现在我想直接从代码初始化它,但我没有找到正确的方法
info := InstructionSet{
Inst: {
"command": "dir",
"timeout": 10,
},
}
这样我得到一个错误提示missing type in composite literal。我尝试了一些变化,但我无法获得正确的方法。
【问题讨论】:
标签: go struct composite-literals