1 Star 1 Fork 0

teamlint/iris

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
di.go 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
package hero
import (
"reflect"
"github.com/kataras/iris/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.
return fn.NumIn() == 1 && IsContext(fn.In(0))
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/teamlint/iris.git
git@gitee.com:teamlint/iris.git
teamlint
iris
iris
v11.1.0

搜索帮助