Passing map parameters in the Golang

I have a simple function that checks if a string is an integer

func testInt(str string, m map[bool]) int { _,e := strconv.ParseInt(str, 0, 64); return m[nil == e] * 7; } 

where the transmitted mapping contains m[true] = 1 , m[false] = 0 . However, when I try to run this Go, it complains

 1: syntax error: unexpected ) 

Or I can’t pass cards as parameters in this way, otherwise I’m doing it completely wrong. In any case, I would really appreciate help

+5
source share
1 answer

A map maps keys to values ​​using syntax

 map[KeyType]ValueType 

(see https://blog.golang.org/go-maps-in-action )

In your function, you did not specify a ValueType , causing this syntax error. It looks like you want map[bool]int .

+8
source

Source: https://habr.com/ru/post/1214711/


All Articles