1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 18:07:01 +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

@@ -1,11 +1,6 @@
package mvc
import (
"reflect"
"github.com/kataras/iris/context"
"github.com/kataras/iris/mvc/di"
)
import "reflect"
var baseControllerTyp = reflect.TypeOf((*BaseController)(nil)).Elem()
@@ -13,12 +8,6 @@ func isBaseController(ctrlTyp reflect.Type) bool {
return ctrlTyp.Implements(baseControllerTyp)
}
var contextTyp = reflect.TypeOf((*context.Context)(nil)).Elem()
func isContext(inTyp reflect.Type) bool {
return inTyp.Implements(contextTyp)
}
func getInputArgsFromFunc(funcTyp reflect.Type) []reflect.Type {
n := funcTyp.NumIn()
funcIn := make([]reflect.Type, n, n)
@@ -27,28 +16,3 @@ func getInputArgsFromFunc(funcTyp reflect.Type) []reflect.Type {
}
return funcIn
}
var (
typeChecker = func(fn reflect.Type) bool {
// valid if that single input arg is a typeof context.Context.
return fn.NumIn() == 1 && isContext(fn.In(0))
}
hijacker = func(fieldOrFuncInput reflect.Type) (*di.BindObject, bool) {
if !isContext(fieldOrFuncInput) {
return nil, false
}
// this is being used on both func injector and struct injector.
// if the func's input argument or the struct's field is a type of Context
// then we can do a fast binding using the ctxValue
// which is used as slice of reflect.Value, because of the final method's `Call`.
return &di.BindObject{
Type: contextTyp,
BindType: di.Dynamic,
ReturnValue: func(ctxValue []reflect.Value) reflect.Value {
return ctxValue[0]
},
}, true
}
)