autowire

package
v0.0.0-...-3a05b22 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AliasKey = "alias"
)
View Source
const CommonActiveProfileMetadataKey = "activeProfile"
View Source
const CommonImplementsMetadataKey = "implements"
View Source
const CommonLoadAtOnceMetadataKey = "loadAtOnce"
View Source
const CommonMetadataKey = "common"
View Source
const MetadataKey = "autowire"

Variables

This section is empty.

Functions

func GetAllWrapperAutowires

func GetAllWrapperAutowires() map[string]WrapperAutowire

func GetBestImplementMapping

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

func GetProxyImplFunction() func(interface{}, interface{}, string) error

func GetSDIDByAlias

func GetSDIDByAlias(alias string) (string, bool)

func GetSDIDByAliasIfNecessary

func GetSDIDByAliasIfNecessary(key string) string

func GetStructDescriptorsMap

func GetStructDescriptorsMap() map[string]*StructDescriptor

func Impl

func Impl(autowireType, key string, param interface{}) (interface{}, error)

func ImplByForce

func ImplByForce(autowireType, key string, param interface{}) (interface{}, error)

func ImplWithProxy

func ImplWithProxy(autowireType, key string, param interface{}) (interface{}, error)

func Load

func Load() error

func RegisterAutowire

func RegisterAutowire(autowire Autowire)

func RegisterProxyFunction

func RegisterProxyFunction(f func(interface{}) interface{})

func RegisterProxyImplFunction

func RegisterProxyImplFunction(f func(interface{}, interface{}, string) error)

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

type AutowireMetadata map[string]interface{}

func ParseAutowireMetadataFromSDMetadata

func ParseAutowireMetadataFromSDMetadata(metadata Metadata) AutowireMetadata

type FieldInfo

type FieldInfo struct {
	FieldName         string
	FieldType         string
	TagKey            string
	TagValue          string
	FieldReflectType  reflect.Type
	FieldReflectValue reflect.Value
}

type InjectPosition

type InjectPosition int
const (
	AfterFactoryCalled     InjectPosition = 0
	AfterConstructorCalled InjectPosition = 1
)

type Metadata

type Metadata map[string]interface{}

Metadata is SD metadata

type MockAutowire

type MockAutowire struct {
	mock.Mock
}

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

type SDIDParser interface {
	Parse(fi *FieldInfo) (string, error)
}

SDIDParser is interface to parse struct descriptor id

type SingletonCache

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 WrapperAutowire interface {
	Autowire

	ImplWithoutParam(sdID string, withProxy, force bool) (interface{}, error)
	ImplWithParam(sdID string, param interface{}, withProxy, force bool) (interface{}, error)
	// contains filtered or unexported methods
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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