How do maps work in Go?

Answer

A map in Go is a built-in hash map (dictionary) type: m := make(map[string]int). Set values with m["key"] = 1 and read with val := m["key"]. To distinguish between a missing key and a zero value, use the two-value form: val, ok := m["key"]ok is false if the key is absent. Delete a key with delete(m, "key"). Maps are not safe for concurrent use — use a sync.RWMutex or sync.Map when multiple goroutines access a map simultaneously.