Go Handy Snippets
Useful Go-isms
Popping an element from a slice via cutting
Combining 3 slices
Single line array swaps
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
Checking if map key exists
Incrementing int values in map
When adding values to a map, go has built in safe guards to ensure the key exists. e.g.