<分区>
这样用reflect可以得到函数名吗?
我是一个新的golang程序员,我不知道如何解决。
代码如下:
type A struct {
Name string
}
func (this *A) Func1(name string) {
fmt.Println(name)
}
func (this *A) Func2(name string, value string) {
fmt.Println(name + ": " + value)
}
func main() {
a := new(A)
v := reflect.ValueOf(a)
for i := 0; i < v.NumMethod(); i++ {
method := v.Method(i)
if method.IsValid() {
t := reflect.TypeOf(method.Interface())
// how to echo the function name of A: Func1,Func2
fmt.Printf("%s %d %d\n", runtime.FuncForPC(method.Pointer()).Name(), t.NumIn(), t.NumOut())
}
}
}