I noticed in the Go docs this definition was included:
type Values map[string][]string
I thought it was a mistake, but then I tried this code and it compiles (Playground):
package main
import "fmt"
func main() {
type MyType map[string][]string
foobar := make(MyType)
fmt.Println(foobar)
}
Is it functionally equivalent to map[string]string
, or is there some difference?
They are different. One is a map of strings to a slice of strings, vs a map of strings to a single string
The []
in []string
denotes a slice
One is a map of string slices while the other is a map of strings. One structure has a single dimension, the map[string][]string
has two. At every key k
you'll have items 0-n
in the slice. So access requires another level of direction like fmt.Println(myInts[k][0])
as apposed to fmt.Println(myInts[k])
. Put data in it and the difference will be more apparent.