Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
MockFieldNameSuffixes = [...]string{"Func", "Handler"} // mock结构体字段名称后缀
)
Functions ¶
This section is empty.
Types ¶
type AroundFunc ¶ added in v0.5.0
func (AroundFunc) Around ¶ added in v0.5.0
func (around AroundFunc) Around(pctx ProxyContext, method reflect.Value, args []reflect.Value) []reflect.Value
type ArounderMap ¶ added in v0.6.0
type ArounderMap map[ProxyContext]AroundFunc
func (ArounderMap) Merge ¶ added in v0.6.0
func (m ArounderMap) Merge(nm ArounderMap) (mr ArounderMap)
type CtxFunc ¶ added in v0.12.0
type CtxFunc func(ctx ProxyContext, method any, args []any) (res []any)
CtxFunc 对于method: func(string, int) (int, error) f := method.(func(string, int) (int, error)) a1 := args[0].(string) a2 := args[1].(int) r1, r2 := f(a1, a2) res = append(res, r1, r2)
type IAroundFunc ¶ added in v0.5.0
type IProxyContext ¶ added in v0.5.0
type Ioc ¶
type Ioc struct {
// contains filtered or unexported fields
}
Ioc 控制反转,Inversion of Control
func (*Ioc) Inject ¶
Inject 注入依赖,传入结构体,根据结构体的字段类型找到对应的provider,执行后将获得的值赋予字段
遍历v的字段,找到字段类型,再根据字段类型找到provider,调用provider获得实例,再把实例值赋给该字段 provider需要在接口定义处注册,注册到一个统一管理的地方 如果provider需要参数,则根据参数类型继续找寻相应的provider,直至初始化完成
func (*Ioc) RegisterProvider ¶
RegisterProvider 注册provider函数,形如`func New(fielda TypeA, fieldb TypeB) (T)`
type IproxyImpl ¶ added in v0.5.0
type ProxyContext ¶ added in v0.5.0
type ProxyContext struct { PkgPath string InterfaceName string // TODO: 接口或结构体的名字,不为空时表示方法,为空时表示函数 MethodName string }
每个包、每个接口、每个方法唯一对应一个方法
func (ProxyContext) LogShortf ¶ added in v0.5.0
func (pctx ProxyContext) LogShortf(format string, args ...any)
func (ProxyContext) Logf ¶ added in v0.5.0
func (pctx ProxyContext) Logf(format string, args ...any)
func (ProxyContext) String ¶ added in v0.5.0
func (pctx ProxyContext) String() string
func (ProxyContext) Uniq ¶ added in v0.12.0
func (pctx ProxyContext) Uniq() string
Click to show internal directories.
Click to hide internal directories.