1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 18:37:05 +00:00

split of the mvc and the new hero package is completed, now handlers with input and output binding feature is a different feature than the mvc, however the mvc controller's methods can use the hero dependency injection as before (v10+)

Former-commit-id: d67f5a5ed9033286bcc4c04f6be612823cba2a57
This commit is contained in:
Gerasimos (Makis) Maropoulos
2017-12-25 20:57:04 +02:00
parent 46505f62db
commit 2ab1456414
33 changed files with 166 additions and 2067 deletions

View File

@@ -4,13 +4,10 @@ import (
"reflect"
"github.com/kataras/iris/context"
"github.com/kataras/iris/core/memstore"
"github.com/kataras/iris/core/router/macro"
"github.com/kataras/iris/core/router/macro/interpreter/ast"
)
// for methods inside a controller.
func getPathParamsForInput(params []macro.TemplateParam, funcIn ...reflect.Type) (values []reflect.Value) {
if len(funcIn) == 0 || len(params) == 0 {
return
@@ -64,43 +61,3 @@ func makeFuncParamGetter(paramType ast.ParamType, paramName string) reflect.Valu
return reflect.ValueOf(fn)
}
// for raw handlers, independent of a controller.
// PathParams is the context's named path parameters, see `PathParamsBinder` too.
type PathParams = context.RequestParams
// PathParamsBinder is the binder which will bind the `PathParams` type value to the specific
// handler's input argument, see `PathParams` as well.
func PathParamsBinder(ctx context.Context) PathParams {
return *ctx.Params()
}
// PathParam describes a named path parameter, it's the result of the PathParamBinder and the expected
// handler func's input argument's type, see `PathParamBinder` too.
type PathParam struct {
memstore.Entry
Empty bool
}
// PathParamBinder is the binder which binds a handler func's input argument to a named path parameter
// based on its name, see `PathParam` as well.
func PathParamBinder(name string) func(ctx context.Context) PathParam {
return func(ctx context.Context) PathParam {
e, found := ctx.Params().GetEntry(name)
if !found {
// useless check here but it doesn't hurt,
// useful only when white-box tests run.
if ctx.Application() != nil {
ctx.Application().Logger().Warnf(ctx.HandlerName()+": expected parameter name '%s' to be described in the route's path in order to be received by the `ParamBinder`, please fix it.\n The main handler will not be executed for your own protection.", name)
}
ctx.StopExecution()
return PathParam{
Empty: true,
}
}
return PathParam{e, false}
}
}