In Go, you can create a map with values of type slice
by initializing a map with make()
and assigning a slice to each key. Here is an example:
main.go157 chars13 lines
This program creates a map m
with string keys and slice values. Then it assigns two slices of integers to keys "foo"
and "bar"
. Finally, it prints the map which should output:
main.go29 chars2 lines
You can modify and access the slices for each key in the same way you would with any regular slice.
gistlibby LogSnag