go - 创建 map[string]struct{} 并赋值

标签 go

我正在使用 github.com/samalba/dockerclient 并想创建一个容器。 因此,该方法是 CreateContainer,它需要一个 ContainerConfig。

ContainerConfig 是一个结构体。还有一个字段Volumes,类型是type map[string] struct{}。

我知道我可以使用 make(map[string]struct{})

创建这样的 map

但是我该如何为 map 赋值呢?

最佳答案

cc := &dockerclient.ContainerConfig{
    // ...
    Volumes: map[string]struct{}{
        "foo": struct{}{},
        "bar": struct{}{},
        // ...
    },
}

关于go - 创建 map[string]struct{} 并赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31761391/

相关文章:

go - 聆听并服务 : Does it allow several connections at the same time?

go - 用结构解码复杂的 JSON 广告

syntax - 首选声明/初始化方法

testing - 集成测试,通配符忽略标签

string - 在 Golang 中将显式字符串传递给 fmt.Sprint

go - 星号在 "Go"中有什么作用?

go - 我如何将时间打印成这种格式 23 :44:22. 184320

go - 实现具有多个生产者的信号量(使用 goroutines)

pointers - 带指针的 Golang 类型断言

go - 多个作业有顺序吗?