我有以下結構:type InstructionSet struct { Inst map[string]interface{}}在地圖中,我想放一些類似的東西InstInst["cmd"] = "dir"Inst["timeout"] = 10現在我想直接從代碼初始化它,但我沒有找到正確的方法來做到這一點 info := InstructionSet{ Inst: { "command": "dir", "timeout": 10, }, }這樣我就得到了一個錯誤,說.我嘗試了一些變體,但我無法找到正確的方法。missing type in composite literal
2 回答

互換的青春
TA貢獻1797條經驗 獲得超6個贊
錯誤指出復合文本中缺少該類型,因此請提供類型:
info := InstructionSet{
Inst: map[string]interface{}{
"command": "dir",
"timeout": 10,
},
}
在Go Playground上嘗試一下。

森欄
TA貢獻1810條經驗 獲得超5個贊
必須使用文本的類型聲明復合文本:
info := InstructionSet{
Inst: map[string]interface{}{
"command": "dir",
"timeout": 10,
},
}
- 2 回答
- 0 關注
- 130 瀏覽
添加回答
舉報
0/150
提交
取消