func (service *Service) callReflectMethod(function setting.FunctionModel, values []interface{}, i int) []reflect.Value {
getFunc := reflect.ValueOf(service).MethodByName(function.MethodName)
// 构造参数列表
entName := fmt.Sprintf("%s", values[i])
args := []reflect.Value{
reflect.ValueOf(entName), //sql value
}
// 使用 Call 方法调用函数,并获取返回值
ret := getFunc.Call(args)
return ret
}
type FunctionModel struct {
MethodName string `yaml:"methodName"`
}
test:
ret := service.callReflectMethod(function, values, i)
fmt.Println(ret[0].String())
test:
ret := service.callReflectMethod(function, values, i)
fmt.Println(ret[0].String())
fmt.Println(ret[1].String())
fmt.Println(ret[2].String())
fmt.Println(ret[3].String())
11-16
179
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-19
894
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-19
1637
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)