← All notes

Go maps

Answer: A Go map is a built-in hash table that maps keys to values.

Basics

m := make(map[string]int)
m["route"] = 66
i := m["route"]
n := len(m)
delete(m, "route")   // no-op if missing
i, ok := m["route"] // ok is false if absent

Keys

A key can be any type that supports ==: strings, numbers, booleans, pointers, structs and arrays of comparable types. Slices, maps and functions cannot be keys.

Reference semantics

Maps are reference types, like pointers or slices. Passing a map to a function lets it modify the caller's map. A nil map reads like an empty map, but writing to it panics, so initialize with make.

Iteration

Sort the keys if you need a stable order.

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Go Authors (go.dev), Go maps in action - The Go Programming Language, CC BY 4.0 (go.dev text); The Go Authors (go.dev), Effective Go - The Go Programming Language, CC BY 4.0 (go.dev text).

Cite this

Permanent ID: iil:note:mthw2x6y

iinventedlight. 2026. "Go maps." iinventedlight Library, iil:note:mthw2x6y, version of 2026-11-04. https://iinventedlight.com/library/notes/go-maps/. License: CC-BY-4.0.

@misc{iil_note_mthw2x6y,
  author = {{iinventedlight}},
  title = {{Go maps}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/go-maps/},
  note = {Permanent ID iil:note:mthw2x6y. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/go-maps.md.