map

A Go collection that stores values by key, such as service name to port number, and looks them up quickly.

In more detail

Write the type as map[KeyType]ValueType. Reading a missing key returns the zero value, so use the comma ok form to tell missing from stored zero. A nil map can be read but writing to it panics, so create it with make or a literal first. Iteration order is deliberately random.

Example

ports := map[string]int{"http": 80, "https": 443}

Related terms

Taught in

References