代码拉取完成,页面将自动刷新
package methodfunc
import (
	"reflect"
	"github.com/kataras/iris/context"
)
// buildMethodCall builds the method caller.
// We have repeated code here but it's the only way
// to support more than one input arguments without performance cost compared to previous implementation.
// so it's hard-coded written to check the length of input args and their types.
func buildMethodCall(a *ast) func(ctx context.Context, f reflect.Value) {
	// if accepts one or more parameters.
	if a.dynamic {
		// if one function input argument then call the function
		// by "casting" (faster).
		if l := len(a.paramKeys); l == 1 {
			paramType := a.paramTypes[0]
			paramKey := a.paramKeys[0]
			if paramType == paramTypeInt {
				return func(ctx context.Context, f reflect.Value) {
					v, _ := ctx.Params().GetInt(paramKey)
					f.Interface().(func(int))(v)
				}
			}
			if paramType == paramTypeLong {
				return func(ctx context.Context, f reflect.Value) {
					v, _ := ctx.Params().GetInt64(paramKey)
					f.Interface().(func(int64))(v)
				}
			}
			if paramType == paramTypeBoolean {
				return func(ctx context.Context, f reflect.Value) {
					v, _ := ctx.Params().GetBool(paramKey)
					f.Interface().(func(bool))(v)
				}
			}
			// string, path...
			return func(ctx context.Context, f reflect.Value) {
				f.Interface().(func(string))(ctx.Params().Get(paramKey))
			}
		}
		// if func input arguments are more than one then
		// use the Call method (slower).
		return func(ctx context.Context, f reflect.Value) {
			f.Call(a.paramValues(ctx))
		}
	}
	// if it's static without any receivers then just call it.
	return func(ctx context.Context, f reflect.Value) {
		f.Interface().(func())()
	}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
 马建仓 AI 助手
马建仓 AI 助手