为什么CreateContainerOptions的卷采用map [string] struct {}?

I've been using the great go-dockerclient] created by fsouza but I'm confused why docker.CreateContainerOptions.Volumes is a map of strings to structs?

The docs don't explain why this is but I'd imagine that you'd just need map[string] => string to map host volumes to container volumes? Or leave the value blank to say that the host volume will be mounted at the same path within the container.

I looked through a bunch of open code on Github with people creating containers but I just saw a lot of examples of people mounting Volumes with just a string and an empty struct as the value.

I'm also new to Go so I might be missing something entirely obvious.

The empty struct is the only type in go that occupies 0 (zero) Bytes of memory.

It is a common idiom to use an empty struct when you want to store something or signal something. But that something should be as small as possible.

In your case

map[string]struct{}

Is used to store just the map's keys with no values associated. This way you can quickly check if the map contains a key or not. (It's basically a set).

Here are a few examples of what you can do with empty structs.

I don't know exactly how this package works, but map[string]struct{} is the Golang idiomatic way of representing a set. So my guess is that the key of the map must contain the full path of the volume...