create a map with a key and value of type int in go

To create a map with a key and value of type int in Go, you can use the built-in make() function. Here's an example code snippet:

main.go
myMap := make(map[string]int)
myMap["key"] = 123 // Set the value for the "key" key
fmt.Println(myMap["key"]) // Output: 123
125 chars
4 lines

In this example, myMap is declared as a map with string type keys and int type values. You can set a value for a key by assigning a value using the key as the index in the map. To retrieve a value for a specific key, use the key as the index and assign the result to a variable.

related categories

gistlibby LogSnag