mirror of
https://github.com/kataras/iris.git
synced 2025-12-21 03:47:04 +00:00
Update to 8.4.0 | New macro type, new high-optimized MVC features. Read HISTORY.md
Former-commit-id: b72a23ba063be60a9750c8b1b0df024b0c8ed549
This commit is contained in:
61
mvc/activator/methodfunc/func_caller.go
Normal file
61
mvc/activator/methodfunc/func_caller.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package methodfunc
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
// FuncCaller is responsible to call the controller's function
|
||||
// which is responsible
|
||||
// for that request for this http method.
|
||||
type FuncCaller interface {
|
||||
// MethodCall fires the actual handler.
|
||||
// The "ctx" is the current context, helps us to get any path parameter's values.
|
||||
//
|
||||
// The "f" is the controller's function which is responsible
|
||||
// for that request for this http method.
|
||||
// That function can accept one parameter.
|
||||
//
|
||||
// The default callers (and the only one for now)
|
||||
// are pre-calculated by the framework.
|
||||
MethodCall(ctx context.Context, f interface{})
|
||||
}
|
||||
|
||||
type callerFunc func(ctx context.Context, f interface{})
|
||||
|
||||
func (c callerFunc) MethodCall(ctx context.Context, f interface{}) {
|
||||
c(ctx, f)
|
||||
}
|
||||
|
||||
func resolveCaller(p pathInfo) callerFunc {
|
||||
// if it's standard `Get`, `Post` without parameters.
|
||||
if p.ParamType == "" {
|
||||
return func(ctx context.Context, f interface{}) {
|
||||
f.(func())()
|
||||
}
|
||||
}
|
||||
|
||||
// remember,
|
||||
// the router already checks for the correct type,
|
||||
// we did pre-calculate everything
|
||||
// and now we will pre-calculate the method caller itself as well.
|
||||
|
||||
if p.ParamType == paramTypeInt {
|
||||
return func(ctx context.Context, f interface{}) {
|
||||
paramValue, _ := ctx.Params().GetInt(paramName)
|
||||
f.(func(int))(paramValue)
|
||||
}
|
||||
}
|
||||
|
||||
if p.ParamType == paramTypeLong {
|
||||
return func(ctx context.Context, f interface{}) {
|
||||
paramValue, _ := ctx.Params().GetInt64(paramName)
|
||||
f.(func(int64))(paramValue)
|
||||
}
|
||||
}
|
||||
|
||||
// else it's string or path, both of them are simple strings.
|
||||
return func(ctx context.Context, f interface{}) {
|
||||
paramValue := ctx.Params().Get(paramName)
|
||||
f.(func(string))(paramValue)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user