Documentation
¶
Index ¶
- Constants
- func GetAllWrapperAutowires() map[string]WrapperAutowire
- func GetBestImplementMapping(interfaceSDID string, activitedOrderedProfiles []string) ([]string, string, error)
- func GetProxyFunction() func(interface{}) interface{}
- func GetProxyImplFunction() func(interface{}, interface{}, string) error
- func GetSDIDByAlias(alias string) (string, bool)
- func GetSDIDByAliasIfNecessary(key string) string
- func GetStructDescriptorsMap() map[string]*StructDescriptor
- func Impl(autowireType, key string, param interface{}) (interface{}, error)
- func ImplByForce(autowireType, key string, param interface{}) (interface{}, error)
- func ImplWithProxy(autowireType, key string, param interface{}) (interface{}, error)
- func Load() error
- func RegisterAutowire(autowire Autowire)
- func RegisterProxyFunction(f func(interface{}) interface{})
- func RegisterProxyImplFunction(f func(interface{}, interface{}, string) error)
- func RegisterStructDescriptor(sd *StructDescriptor)
- type Autowire
- type AutowireMetadata
- type FieldInfo
- type InjectPosition
- type Metadata
- type MockAutowire
- func (_m *MockAutowire) CanBeEntrance() bool
- func (_m *MockAutowire) Construct(sdID string, impledPtr interface{}, param interface{}) (interface{}, error)
- func (_m *MockAutowire) Factory(sdID string) (interface{}, error)
- func (_m *MockAutowire) GetAllStructDescriptors() map[string]*StructDescriptor
- func (_m *MockAutowire) InjectPosition() InjectPosition
- func (_m *MockAutowire) IsSingleton() bool
- func (_m *MockAutowire) ParseParam(sdID string, fi *FieldInfo) (interface{}, error)
- func (_m *MockAutowire) ParseSDID(field *FieldInfo) (string, error)
- func (_m *MockAutowire) TagKey() string
- type ParamLoader
- type SDIDParser
- type SingletonCache
- type StructDescriptor
- type WrapperAutowire
- type WrapperAutowireImpl
Constants ¶
const (
AliasKey = "alias"
)
const CommonActiveProfileMetadataKey = "activeProfile"
const CommonImplementsMetadataKey = "implements"
const CommonLoadAtOnceMetadataKey = "loadAtOnce"
const CommonMetadataKey = "common"
const MetadataKey = "autowire"
Variables ¶
This section is empty.
Functions ¶
func GetAllWrapperAutowires ¶
func GetAllWrapperAutowires() map[string]WrapperAutowire
func GetBestImplementMapping ¶ added in v1.0.1
func GetBestImplementMapping(interfaceSDID string, activitedOrderedProfiles []string) ([]string, string, error)
GetBestImplementMapping get best impl struct sdids slice and profile of given interfaceSDID and activitedOrderedProfiles if there isn't any matched implementation, even "_default" impl is not found, an error occurs return values are bestMatchesStructImplSDIDs, bestMatchProfile, error
func GetProxyFunction ¶
func GetProxyFunction() func(interface{}) interface{}
func GetProxyImplFunction ¶ added in v1.0.1
func GetSDIDByAlias ¶
func GetStructDescriptorsMap ¶
func GetStructDescriptorsMap() map[string]*StructDescriptor
func ImplByForce ¶ added in v1.0.1
func ImplWithProxy ¶
func RegisterAutowire ¶
func RegisterAutowire(autowire Autowire)
func RegisterProxyFunction ¶
func RegisterProxyFunction(f func(interface{}) interface{})
func RegisterProxyImplFunction ¶ added in v1.0.1
func RegisterStructDescriptor ¶
func RegisterStructDescriptor(sd *StructDescriptor)
Types ¶
type Autowire ¶
type Autowire interface {
TagKey() string
// IsSingleton means the struct of this autowire type can only have one object globally, which is only created once.
IsSingleton() bool
/*
CanBeEntrance means the struct is loaded at the start of application.
By default, only rpc-server can be entrance.
*/
CanBeEntrance() bool
/*
Factory is contruct function of struct of this autowire type
*/
Factory(sdID string) (interface{}, error)
/*
ParseSDID parse FieldInfo to struct descriptorId
if field type is struct ptr like
MyStruct *MyStruct `autowire-type:"MyStruct"`
FieldInfo would be
FieldInfo.FieldName == "MyStruct"
FieldInfo.FieldType == "" // ATTENTION!!!
FieldInfo.TagKey == "autowire-type"
FieldInfo.TagValue == "MyStruct"
You should make sure tag value contains ptr type if you use it.
if field type is interface like
MyStruct MyInterface ` `autowire-type:"MyStruct"`
FieldInfo would be
FieldInfo.FieldName == "MyStruct"
FieldInfo.FieldType == "MyInterface"
FieldInfo.TagKey == "autowire-type"
FieldInfo.TagValue == "MyStruct"
*/
ParseSDID(field *FieldInfo) (string, error)
ParseParam(sdID string, fi *FieldInfo) (interface{}, error)
Construct(sdID string, impledPtr, param interface{}) (interface{}, error)
GetAllStructDescriptors() map[string]*StructDescriptor
InjectPosition() InjectPosition
}
Autowire
type AutowireMetadata ¶ added in v1.0.1
type AutowireMetadata map[string]interface{}
func ParseAutowireMetadataFromSDMetadata ¶ added in v1.0.1
func ParseAutowireMetadataFromSDMetadata(metadata Metadata) AutowireMetadata
type InjectPosition ¶
type InjectPosition int
const ( AfterFactoryCalled InjectPosition = 0 AfterConstructorCalled InjectPosition = 1 )
type MockAutowire ¶
MockAutowire is an autogenerated mock type for the MockAutowire type
func NewMockAutowire ¶
func NewMockAutowire(t testing.TB) *MockAutowire
NewMockAutowire creates a new instance of MockAutowire. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations.
func (*MockAutowire) CanBeEntrance ¶
func (_m *MockAutowire) CanBeEntrance() bool
CanBeEntrance provides a mock function with given fields:
func (*MockAutowire) Construct ¶
func (_m *MockAutowire) Construct(sdID string, impledPtr interface{}, param interface{}) (interface{}, error)
Construct provides a mock function with given fields: sdID, impledPtr, param
func (*MockAutowire) Factory ¶
func (_m *MockAutowire) Factory(sdID string) (interface{}, error)
Factory provides a mock function with given fields: sdID
func (*MockAutowire) GetAllStructDescriptors ¶
func (_m *MockAutowire) GetAllStructDescriptors() map[string]*StructDescriptor
GetAllStructDescriptors provides a mock function with given fields:
func (*MockAutowire) InjectPosition ¶
func (_m *MockAutowire) InjectPosition() InjectPosition
InjectPosition provides a mock function with given fields:
func (*MockAutowire) IsSingleton ¶
func (_m *MockAutowire) IsSingleton() bool
IsSingleton provides a mock function with given fields:
func (*MockAutowire) ParseParam ¶
func (_m *MockAutowire) ParseParam(sdID string, fi *FieldInfo) (interface{}, error)
ParseParam provides a mock function with given fields: sdID, fi
func (*MockAutowire) ParseSDID ¶
func (_m *MockAutowire) ParseSDID(field *FieldInfo) (string, error)
ParseSDID provides a mock function with given fields: field
func (*MockAutowire) TagKey ¶
func (_m *MockAutowire) TagKey() string
TagKey provides a mock function with given fields:
type ParamLoader ¶
type ParamLoader interface {
Load(sd *StructDescriptor, fi *FieldInfo) (interface{}, error)
}
ParamLoader is interface to load param
type SDIDParser ¶
SDIDParser is interface to parse struct descriptor id
type SingletonCache ¶ added in v1.0.2
type SingletonCache struct {
RawPtr interface{}
ProxyPtr interface{}
}
type StructDescriptor ¶
type StructDescriptor struct {
SDID string
Factory func() interface{} // raw struct
ParamFactory func() interface{}
ParamLoader ParamLoader
ConstructFunc func(impl interface{}, param interface{}) (interface{}, error) // injected
DestroyFunc func(impl interface{})
Alias string // alias of SDID
DisableProxy bool // disable proxy and aop
Metadata Metadata
// contains filtered or unexported fields
}
func GetStructDescriptor ¶
func GetStructDescriptor(sdid string) *StructDescriptor
func (*StructDescriptor) ID ¶
func (ed *StructDescriptor) ID() string
type WrapperAutowire ¶
type WrapperAutowireImpl ¶
type WrapperAutowireImpl struct {
Autowire
// contains filtered or unexported fields
}
func (*WrapperAutowireImpl) ImplWithParam ¶
func (w *WrapperAutowireImpl) ImplWithParam(sdID string, param interface{}, withProxy, force bool) (interface{}, error)
ImplWithParam is used to get impled struct with param
func (*WrapperAutowireImpl) ImplWithoutParam ¶
func (w *WrapperAutowireImpl) ImplWithoutParam(sdID string, withProxy, force bool) (interface{}, error)
ImplWithoutParam is used to create param from field without param