在Golang中传递地图参数

Dro*_*dOS 7 go

我有一个简单的函数来测试字符串是否是整数

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

传递的地图包含的地方m[true] = 1,m[false] = 0.但是,当我试图运行这个Go抱怨时

1: syntax error: unexpected )
Run Code Online (Sandbox Code Playgroud)

我不能以这种方式传递地图作为参数,否则我这样做完全错了.无论如何,我非常感谢一些帮助

Vit*_*ius 14

map键映射到值,使用语法

map[KeyType]ValueType
Run Code Online (Sandbox Code Playgroud)

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

在您的函数中,您尚未指定a ValueType,导致此语法错误.看起来你想要一个map[bool]int.