inject

package
v0.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2021 License: Apache-2.0 Imports: 6 Imported by: 1

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

type AroundFunc func(pctx ProxyContext, method reflect.Value, args []reflect.Value) []reflect.Value

func (AroundFunc) Around added in v0.5.0

func (around AroundFunc) Around(pctx ProxyContext, method reflect.Value, args []reflect.Value) []reflect.Value

type AroundFuncMock added in v0.5.0

type AroundFuncMock struct {
	AroundFunc func(pctx ProxyContext, method reflect.Value, args []reflect.Value) []reflect.Value
}

func (*AroundFuncMock) Around added in v0.5.0

func (mockRecv *AroundFuncMock) Around(pctx ProxyContext, method reflect.Value, args []reflect.Value) []reflect.Value

type AroundMockMock added in v0.5.0

type AroundMockMock struct {
	AfterFunc func(pctx ProxyContext)

	BeforeFunc func(pctx ProxyContext)
}

func (*AroundMockMock) After added in v0.5.0

func (mockRecv *AroundMockMock) After(pctx ProxyContext)

func (*AroundMockMock) Before added in v0.5.0

func (mockRecv *AroundMockMock) Before(pctx ProxyContext)

type Arounder added in v0.5.0

type Arounder interface {
	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 ArounderMock added in v0.5.0

type ArounderMock struct {
	AroundFunc func(pctx ProxyContext, method reflect.Value, args []reflect.Value) []reflect.Value
}

func (*ArounderMock) Around added in v0.5.0

func (mockRecv *ArounderMock) Around(pctx ProxyContext, method reflect.Value, args []reflect.Value) []reflect.Value

type ArounderMockMock added in v0.5.0

type ArounderMockMock struct {
	AroundFunc func(pctx ProxyContext, method reflect.Value, args []reflect.Value) []reflect.Value
}

func (*ArounderMockMock) Around added in v0.5.0

func (mockRecv *ArounderMockMock) Around(pctx ProxyContext, method reflect.Value, args []reflect.Value) []reflect.Value

type IAroundFunc added in v0.5.0

type IAroundFunc interface {
	Around(pctx ProxyContext, method reflect.Value, args []reflect.Value) []reflect.Value
}

type IAroundMock added in v0.5.0

type IAroundMock interface {
	After(pctx ProxyContext)
	Before(pctx ProxyContext)
}

type IArounderMock added in v0.5.0

type IArounderMock interface {
	Around(pctx ProxyContext, method reflect.Value, args []reflect.Value) []reflect.Value
}

type IIoc added in v0.5.0

type IIoc interface {
	Inject(v interface{}) (err error)
	RegisterProvider(v interface{}) (err error)
}

type IIocMock added in v0.5.0

type IIocMock interface {
	Inject(v interface{}) (err error)
	RegisterProvider(v interface{}) (err error)
}

type IProxyContext added in v0.5.0

type IProxyContext interface {
	LogShortf(format string, args ...interface{})
	Logf(format string, args ...interface{})
	String() string
}

type IProxyContextMock added in v0.5.0

type IProxyContextMock interface {
	Logf(format string, args ...interface{})
	String() string
}

type IProxyMock added in v0.5.0

type IProxyMock interface {
	Around(provider interface{}, mock interface{}, arounder Arounder) interface{}
}

type Ioc

type Ioc struct {
	// contains filtered or unexported fields
}

Ioc 控制反转,Inversion of Control

func NewIoc

func NewIoc(
	enableUnexportedFieldSetValue bool,
) *Ioc

func (*Ioc) Inject

func (ioc *Ioc) Inject(v interface{}) (err error)

Inject 注入依赖

遍历v的字段,找到字段类型,再根据字段类型找到provider,调用provider获得实例,再把实例值赋给该字段 provider需要在接口定义处注册,注册到一个统一管理的地方 如果provider需要参数,则根据参数类型继续找寻相应的provider,直至初始化完成

func (*Ioc) RegisterProvider

func (ioc *Ioc) RegisterProvider(v interface{}) (err error)

RegisterProvider 注册provider

type IocMock added in v0.5.0

type IocMock struct {
	InjectFunc func(v interface{}) (err error)

	RegisterProviderFunc func(v interface{}) (err error)
}

func (*IocMock) Inject added in v0.5.0

func (mockRecv *IocMock) Inject(v interface{}) (err error)

func (*IocMock) RegisterProvider added in v0.5.0

func (mockRecv *IocMock) RegisterProvider(v interface{}) (err error)

type IocMockMock added in v0.5.0

type IocMockMock struct {
	InjectFunc func(v interface{}) (err error)

	RegisterProviderFunc func(v interface{}) (err error)
}

func (*IocMockMock) Inject added in v0.5.0

func (mockRecv *IocMockMock) Inject(v interface{}) (err error)

func (*IocMockMock) RegisterProvider added in v0.5.0

func (mockRecv *IocMockMock) RegisterProvider(v interface{}) (err error)

type IproxyImpl added in v0.5.0

type IproxyImpl interface {
	Around(provider interface{}, mock interface{}, arounder Arounder) interface{}
}

type Proxy added in v0.5.0

type Proxy interface {
	Around(provider interface{}, mock interface{}, arounder Arounder) interface{}
}

Proxy 在层间依赖调用时插入钩子调用,类似AOP

func NewProxy added in v0.5.0

func NewProxy() Proxy

type ProxyContext added in v0.5.0

type ProxyContext struct {
	PkgPath       string
	InterfaceName string
	MethodName    string
}

func (ProxyContext) LogShortf added in v0.5.0

func (pctx ProxyContext) LogShortf(format string, args ...interface{})

func (ProxyContext) Logf added in v0.5.0

func (pctx ProxyContext) Logf(format string, args ...interface{})

func (ProxyContext) String added in v0.5.0

func (pctx ProxyContext) String() string

type ProxyContextMock added in v0.5.0

type ProxyContextMock struct {
	LogShortfFunc func(format string, args ...interface{})

	LogfFunc func(format string, args ...interface{})

	StringFunc func() string
}

func (*ProxyContextMock) LogShortf added in v0.5.0

func (mockRecv *ProxyContextMock) LogShortf(format string, args ...interface{})

func (*ProxyContextMock) Logf added in v0.5.0

func (mockRecv *ProxyContextMock) Logf(format string, args ...interface{})

func (*ProxyContextMock) String added in v0.5.0

func (mockRecv *ProxyContextMock) String() string

type ProxyContextMockMock added in v0.5.0

type ProxyContextMockMock struct {
	LogfFunc func(format string, args ...interface{})

	StringFunc func() string
}

func (*ProxyContextMockMock) Logf added in v0.5.0

func (mockRecv *ProxyContextMockMock) Logf(format string, args ...interface{})

func (*ProxyContextMockMock) String added in v0.5.0

func (mockRecv *ProxyContextMockMock) String() string

type ProxyMock added in v0.5.0

type ProxyMock struct {
	AroundFunc func(provider interface{}, mock interface{}, arounder Arounder) interface{}
}

func (*ProxyMock) Around added in v0.5.0

func (mockRecv *ProxyMock) Around(provider interface{}, mock interface{}, arounder Arounder) interface{}

type ProxyMockMock added in v0.5.0

type ProxyMockMock struct {
	AroundFunc func(provider interface{}, mock interface{}, arounder Arounder) interface{}
}

func (*ProxyMockMock) Around added in v0.5.0

func (mockRecv *ProxyMockMock) Around(provider interface{}, mock interface{}, arounder Arounder) interface{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL