正确初始化map[string]接口结构

cip*_*ips 2 struct go composite-literals

我有以下结构:

type InstructionSet struct {
    Inst map[string]interface{}
}
Run Code Online (Sandbox Code Playgroud)

Inst地图上我想放一些类似的东西

Inst["cmd"] = "dir"
Inst["timeout"] = 10
Run Code Online (Sandbox Code Playgroud)

现在我想直接从代码初始化它,但我没有找到正确的方法来做到这一点

    info := InstructionSet{
        Inst: {
            "command": "dir",
            "timeout": 10,
            },
    }
Run Code Online (Sandbox Code Playgroud)

这样我就得到一个错误说missing type in composite literal. 我尝试了一些变化,但我找不到正确的方法。

icz*_*cza 5

该错误表明复合文字中缺少类型,因此请提供类型:

info := InstructionSet{
    Inst: map[string]interface{}{
        "command": "dir",
        "timeout": 10,
    },
}
Run Code Online (Sandbox Code Playgroud)

在Go Playground上尝试一下。