我有一个定义了函数的Go程序.我还有一张应该有每个功能键的地图.我怎样才能做到这一点?
我试过这个,但这不起作用.
func a(param string) {
}
m := map[string] func {
'a_func': a,
}
for key, value := range m {
if key == 'a_func' {
value(param)
}
}
我MethodByName()在http://golang.org/pkg/reflect/#Value.MethodByName找到了一个函数调用,但它并不是我想要的!(也许是因为我不知道如何使用它...我找不到它的任何例子).我想要的是:
type MyStruct struct {
//some feilds here
}
func (p *MyStruct) MyMethod {
println("My statement.");
}
CallFunc("MyStruct", "MyMethod");
//print out "My statement."
Run Code Online (Sandbox Code Playgroud)
所以我想,首先我需要一些类似的东西StructByName(),之后使用它MethodByName(),是吧!?