---
source: https://iinventedlight.com/library/notes/go-maps.md
title: "Go maps"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC BY 4.0 (go.dev text); prose restates cited source lines"
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: Go"
tags: ['go', 'maps', 'hash-table', 'data-structures']
sources:
  - id: S1
    title: "Go maps in action - The Go Programming Language"
    publisher: The Go Authors (go.dev)
    url: https://go.dev/blog/maps
    accessed: 2026-11-04
    license: "CC BY 4.0 (go.dev text)"
  - id: S2
    title: "Effective Go - The Go Programming Language"
    publisher: The Go Authors (go.dev)
    url: https://go.dev/doc/effective_go
    accessed: 2026-11-04
    license: "CC BY 4.0 (go.dev text)"
---
# Go maps

**Answer:** A Go map is a built-in hash table that maps keys to values.

## Basics

```go
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).
