Go Handy Snippets
Useful Go-isms
Maps must be initialized
Map types are reference types, like pointers or slices, and so the value of m above is nil; it doesn’t point to an initialized map. A nil map behaves like an empty map when reading, but attempts to write to a nil map will cause a runtime panic; don’t do that. To initialize a map, use the built in make function
1// go will panic
2// error: assignment to entry in nil map
3var data map[string]any
4data["foo"] = "bar"
go