October 2016
Beginner
348 pages
6h 31m
English
The Go map is a composite type that is used as containers for storing unordered elements of the same type indexed by an arbitrary key value. The following code snippet shows a variety of map variables declarations with a variety of key types:
var (
legends map[int]string
histogram map[string]int
calibration map[float64]bool
matrix map[[2][2]int]bool // map with array key type
table map[string][]string // map of string slices
// map (with struct key) of map of string
log map[struct{name string}]map[string]string
)
golang.fyi/ch07/maptypes.go
The previous code snippet shows several variables declared as maps of different types with a variety of key types. In general, map type is specified as follows:
map[<key_type>]<element_type>
The
Read now
Unlock full access