Is it possible to declare a map with key value pairs?
Something like this
var env map[string]int{
"key0": 10,
"key1": 398
}
Is it possible to declare a map with key value pairs?
Something like this
var env map[string]int{
"key0": 10,
"key1": 398
}
Yes, you can declare a map with name value pairs. You can use a variable declaration with a map composite literal:
var env = map[string]int{
"key0": 10,
"key1": 398,
}
or a short variable declaration with the composite literal:
env := map[string]int{
"key0": 10,
"key1": 398,
}
The short variable declaration can only be used in a function. The variable declaration can be used in functions and at package level.
Also note the added "," following the 398.