为了得到返回值作为ModuleInfo,获得潜在价值的第一个返回值的类型断言该接口值ModuleInfo:
// mi has type core.ModuleInfomi := method.Func.Call(in)[0].Interface().(core.ModuleInfo)
在Playground上运行它。
您可以通过将方法类型声明为具有正确签名的函数并直接调用该函数来剪切一些反射代码:
for i := 0; i < miType.NumMethod(); i++ { method := miType.Method(i).Func.Interface().(func(core.ModuleInfo) core.ModuleInfo) mi := method(core.ModuleInfo{}) fmt.Println("Version", mi.Version) fmt.Println("Priority", mi.Priority) fmt.Println("")}在操场上运行



