我想从函数名调用现有库中的函数。在golang中,只要从methodname调用method就OK了,因为reflectpackage有(vValue)MethodByName(namestring)。但是,对于调用方法,所有方法参数都应该是reflect.Value。如何调用参数不是reflect.Value的函数。packagemain//-------------------------------//Exampleofexistinglibrary//-------------------------------typeClientstruct{idstring}typeMet
给定typeRunnableinterface{Run()}typeTstruct{Zstruct{Aint}}func(tT)Run(){t.Z.A=1}funcmain(){t:=reflect.TypeOf(T{})varvreflect.Valuev=reflect.New(t).Elem()runnable:=v.Interface().(Runnable)runnable.Run()最后,有没有办法检索Z及其由Run()方法设置的字段值?我正在实现一个API命令模式,所以T可以是RegisterCommand、LoginCommand、LogoutCommand等。Z是“输
给定typeRunnableinterface{Run()}typeTstruct{Zstruct{Aint}}func(tT)Run(){t.Z.A=1}funcmain(){t:=reflect.TypeOf(T{})varvreflect.Valuev=reflect.New(t).Elem()runnable:=v.Interface().(Runnable)runnable.Run()最后,有没有办法检索Z及其由Run()方法设置的字段值?我正在实现一个API命令模式,所以T可以是RegisterCommand、LoginCommand、LogoutCommand等。Z是“输