I'm trying to use a map[string]int to count elements in a test in Go, but the values inside my map are always 0:
var counts = make(map[string]int)
func mockCheckTokenExists(counts map[string]int) func(token string) (bool, error) {
return func(token string) (bool, error) {
fmt.Println("count: ", counts[token])
if token == tokenPresent0Times {
return false, nil
} else if token == tokenPresent1Times && counts[tokenPresent1Times] == 1 {
return false, nil
}
counts[token]++;
return true, nil
}
}
the function returned by this one is passed as parameter to another one.
when printing the counts at each call they are always 0. What is wrong with this code?