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
- id: C1 claim: Go provides a built-in map type that implements a hash table. source: S1 evidence: "Go provides a built-in map type that implements a hash table."
- id: C2 claim: delete does nothing if the key doesn't exist. source: S1 evidence: "will do nothing if the specified key doesn’t exist"
- id: C3 claim: Maps are not safe for concurrent use. source: S1 evidence: "Maps are not safe for concurrent use:"
- id: C4 claim: Map iteration order is not specified. source: S1 evidence: "the iteration order is not specified and is not guaranteed to be the same"
- id: C5 claim: Keys can be any type with an equality operator. source: S2 evidence: "The key can be of any type for which the equality operator is defined,"
- id: C6 claim: Effective Go names the comma ok idiom. source: S2 evidence: "For obvious reasons this is called the “comma ok” idiom."
Sources
- [S1] Go maps in action - The Go Programming Language. The Go Authors (go.dev). https://go.dev/blog/maps . License: CC BY 4.0 (go.dev text). Accessed 2026-11-04.
- [S2] Effective Go - The Go Programming Language. The Go Authors (go.dev). https://go.dev/doc/effective_go . License: CC BY 4.0 (go.dev text). Accessed 2026-11-04.
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
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.},
}
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.