Sorry, I post my question again.
I have been read the solution before I ask my question. I think it can not help me because my question is how to pass a function as a parameter? I don't want to call it.
I just want to pass it to another function that I can't edit (or I don't want to edit), and I want to use a string variable to point the function
funcName := "Go"
m.set(t.funcName)
I think this is different from this question Call a Struct and its Method by name in Go?
for example
I have a function like:
type Context struct{}
type myclass struct{}
type Handler func (c *Context)
func (r *myclass) set(ch Handler) {
}
I can use this way:
type testclass struct {}
func (t *testclass) Go(c *Context){
println("Hello");
}
t := &testclass{}
m := &myclass{}
m.set(t.Go)
and my question is
type testclass struct{}
func (t *testclass) Go(c *Context){
println("Hello");
}
t := &testclass{}
m := &myclass{}
funcName := "Go"
m.set(t.funcName)
any way can do this?
reflect?or what?
if it is impossible, there are other ways to do this?
thanks