HashMaps are very popular, and extremely important data structures in any programming language. A map is a collection of key value pairs, where you use the key to obtain the value that corresponds to it. Using maps greatly speeds up your software due to the fact that with a map, retrieving a value through a key is a very quick operation.
In Go, you can declare a map like this:
var myMap map[int]string
The preceding code declares a map where the keys are of type int, and the values are of type string.
You can initialize a map using the make function:
myMap = make(map[int]string)
You can't use a map before you initialize it, otherwise an error will be thrown. Here is another way to initialize a map:
myMap = map[int]string{}
What if you want to initialize the map with some values? You can do this: