Go maps
Go maps is the equivalent of hash tables from other languages essentially. We create maps by using the make
keyword.
Creating a map in Go
var idMap map[key]value
idMap = make (map[key]value)
or by using literals
idMap := map[key]value
Adding and removing a value to the map in Go
idMap["key2"] = value2
delete(idMap, "key")
Accessing a map in Go
fmt.Println(idMap["key"]) <- this will print the value of the key
Working with maps
len(idMap)
for key, value := range idMap {
fmt.Println(key,value)
}