I'm a newbie in golang and this part of a tour of Go about mutating maps is killing my world of pink ponies.
Here is an example of the problem:
package main
import "fmt"
func main() {
a := make([]int, 10)
fmt.Println(a[123]) //panic: runtime error: index out of range, good
b := make(map[int]int, 10)
fmt.Println(b[123]) // 0 ? WHAAAT? Not nil, not panic?
}
I know, that I can check element existence with second value, like this:
v, ok := b[11]
if (!ok) {
// do something strange
}
But why I need to do this every time in every place where I need to get something from map? I consider maps like associative arrays, but this behavior is really strange.
How can I make a map with panic-level checking of keys?