我正在尝试使用构建一个简单的 golang 程序 go-dockerclientpackage mainimport ( docker "github.com/fsouza/go-dockerclient")func main () { h := &docker.HostConfig { Memory: 4194304, MemorySwap: -1, CPUShares: 5, NetworkMode: "host", } client, err := docker.NewClient("unix:///var/run/docker.sock") config := &docker.Config { Env: ["FOO=foo"], Image: "redis", } opts := docker.CreateContainerOptions { Config: config, HostConfig: hostConfig, } container, _ := client.CreateContainer(opts) err = client.StartContainer(container.ID)}这给了我::~/gosrc/src/github.com/achanda$ go build# github.com/achanda./main.go:16: syntax error: unexpected comma./main.go:22: non-declaration statement outside function body./main.go:23: non-declaration statement outside function body./main.go:24: non-declaration statement outside function body./main.go:25: syntax error: unexpected }我似乎没有发现语法有什么问题(虽然这确实是个菜鸟)。问题是什么?
1 回答
繁花不似锦
TA贡献1851条经验 获得超4个赞
切片文字应如下所示:
[]string{"a", "b", "c"}
不是这样的:
["a", "b", "c"]
所以改变这个:
Env: ["FOO=foo"],
对此:
Env: []string{"FOO=foo"},
- 1 回答
- 0 关注
- 196 浏览
添加回答
举报
0/150
提交
取消