iris/hero/di.go
Gerasimos (Makis) Maropoulos 3945fa68d1 obey the vote of @1370 (77-111 at this point) - add import suffix on iris repository
We have to do the same on iris-contrib/examples, iris-contrib/middleware and e.t.c.


Former-commit-id: 0860688158f374bc137bc934b81b26dcd0e10964
2019-10-25 01:27:02 +03:00

44 lines
1.4 KiB
Go

package hero
import (
"reflect"
"github.com/kataras/iris/v12/hero/di"
)
func init() {
di.DefaultHijacker = func(fieldOrFuncInput reflect.Type) (*di.BindObject, bool) {
// if IsExpectingStore(fieldOrFuncInput) {
// return &di.BindObject{
// Type: memstoreTyp,
// BindType: di.Dynamic,
// ReturnValue: func(ctxValue []reflect.Value) reflect.Value {
// // return ctxValue[0].MethodByName("Params").Call(di.EmptyIn)[0]
// return ctxValue[0].MethodByName("Params").Call(di.EmptyIn)[0].Field(0) // the Params' memstore.Store.
// },
// }, true
// }
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
}
di.DefaultTypeChecker = func(fn reflect.Type) bool {
// valid if that single input arg is a typeof context.Context
// or first argument is context.Context and second argument is a variadic, which is ignored (i.e new sessions#Start).
return (fn.NumIn() == 1 || (fn.NumIn() == 2 && fn.IsVariadic())) && IsContext(fn.In(0))
}
}