Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterModel(model interface{}, aliases ...string) (err error)
- type ClassicFactory
- func (p *ClassicFactory) ContainsObject(name string) bool
- func (p *ClassicFactory) Define(name string, scope Scope, model string, opts ...DefinitionOption) (err error)
- func (p *ClassicFactory) GetAliases(name string) (aliases []string, err error)
- func (p *ClassicFactory) GetObject(name string, opts ...Options) (obj interface{}, err error)
- func (p *ClassicFactory) GetType(name string) (typ reflect.Type)
- func (p *ClassicFactory) IsPrototype(name string) bool
- func (p *ClassicFactory) IsSingleton(name string) bool
- func (p *ClassicFactory) IsTypeMatch(name string, typ reflect.Type) bool
- type ClassicModelProvider
- type DefinitionOption
- type Factory
- type ModelProvider
- type NewObjectFunc
- type ObjectDefinition
- func (p *ObjectDefinition) Aliases() []string
- func (p *ObjectDefinition) InitialFuncName() string
- func (p *ObjectDefinition) IsTypeMatch(typ reflect.Type) bool
- func (p *ObjectDefinition) Name() string
- func (p *ObjectDefinition) NewObjectFunc() NewObjectFunc
- func (p *ObjectDefinition) Scope() Scope
- func (p *ObjectDefinition) String() string
- func (p *ObjectDefinition) Type() reflect.Type
- type ObjectInstance
- type Options
- type Scope
Constants ¶
View Source
const (
ErrNamespace = "gogap-factory"
)
Variables ¶
View Source
var ( ErrEmptyObjectDefinitionName = errors.TN(ErrNamespace, 1000, "empty object definition name") ErrObjectDefinitionAlreadyRegistered = errors.TN(ErrNamespace, 1001, "object definition already registered, name: {{.name}}, type: {{.type}}") ErrObjectNotExist = errors.TN(ErrNamespace, 1002, "object not exist, name: {{.name}}") ErrObjectDefintionNotExist = errors.TN(ErrNamespace, 1003, "object definition not exist, name: {{.name}}") ErrReflectValueNotValid = errors.TN(ErrNamespace, 1004, "reflect value not valid") ErrStructFieldNotExist = errors.TN(ErrNamespace, 1005, "struct field not exist, field name: {{.name}}") ErrObjectMustBeStruct = errors.TN(ErrNamespace, 1007, "object must be struct, name: {{.name}}") ErrCouldNotSetFiledOfNilObject = errors.TN(ErrNamespace, 1008, "object is nil, could not inject filed value, field: {{.field}}") ErrCouldNotSetZeroNumFieldObject = errors.TN(ErrNamespace, 1009, "file number is zero, could not inject filed value, filed: {{.field}}") ErrObjectIsNotStruct = errors.TN(ErrNamespace, 1010, "the object must be a struct or ptr to struct") ErrRefObjectShouldBePtr = errors.TN(ErrNamespace, 1011, "ref object should be ptr") ErrRefFieldShouldBePtr = errors.TN(ErrNamespace, 1012, "ref field should be ptr") ErrEmptyFieldName = errors.TN(ErrNamespace, 1013, "empty field name") ErrBadFieldName = errors.TN(ErrNamespace, 1014, "bad field name, field name: {{.name}}") ErrModelAlreayRegistered = errors.TN(ErrNamespace, 1015, "model already registered, name: {{.name}}, type: {{.type}}") ErrModleAliasAlreadyExist = errors.TN(ErrNamespace, 1016, "model alias already exist and model name not match, original name: {{.originalName}}, new name: {{.newName}}") ErrModelNameIsEmpty = errors.TN(ErrNamespace, 1017, "model name is empty") ErrModelNotExist = errors.TN(ErrNamespace, 1018, "model of {{.name}} not exist") ErrRefDefinitionNameIsEmpty = errors.TN(ErrNamespace, 1019, "ref definition name is empty, def name: {{.name}}") ErrFiledAreadyRef = errors.TN(ErrNamespace, 1020, "field already ref others definition, original ref defition name: {{.name}}") ErrFieldIsZeroValue = errors.TN(ErrNamespace, 1021, "filed is zero value, field name: {{.name}}") ErrBadRefOrderLength = errors.TN(ErrNamespace, 1022, "ref order does not equal definition refs") ErrRefOrderContainNonExistRef = errors.TN(ErrNamespace, 1023, "ref order contain non exist def ref, name: {{.name}}") )
Functions ¶
func RegisterModel ¶
Types ¶
type ClassicFactory ¶
type ClassicFactory struct {
// contains filtered or unexported fields
}
func (*ClassicFactory) ContainsObject ¶
func (p *ClassicFactory) ContainsObject(name string) bool
func (*ClassicFactory) Define ¶
func (p *ClassicFactory) Define( name string, scope Scope, model string, opts ...DefinitionOption) (err error)
func (*ClassicFactory) GetAliases ¶
func (p *ClassicFactory) GetAliases(name string) (aliases []string, err error)
func (*ClassicFactory) GetObject ¶
func (p *ClassicFactory) GetObject(name string, opts ...Options) (obj interface{}, err error)
func (*ClassicFactory) IsPrototype ¶
func (p *ClassicFactory) IsPrototype(name string) bool
func (*ClassicFactory) IsSingleton ¶
func (p *ClassicFactory) IsSingleton(name string) bool
func (*ClassicFactory) IsTypeMatch ¶
func (p *ClassicFactory) IsTypeMatch(name string, typ reflect.Type) bool
type ClassicModelProvider ¶
type ClassicModelProvider struct {
// contains filtered or unexported fields
}
func (*ClassicModelProvider) Get ¶
func (p *ClassicModelProvider) Get(name string) (typ reflect.Type, exist bool)
func (*ClassicModelProvider) Register ¶
func (p *ClassicModelProvider) Register(model interface{}, aliases ...string) (err error)
type DefinitionOption ¶
type DefinitionOption struct {
// contains filtered or unexported fields
}
func DefOptOfInitialFunc ¶
func DefOptOfInitialFunc(fnName string) DefinitionOption
func DefOptOfNewObjectFunc ¶
func DefOptOfNewObjectFunc(fn NewObjectFunc) DefinitionOption
func DefOptOfObjectRef ¶
func DefOptOfObjectRef(fieldName string, refDefName string, opts ...Options) DefinitionOption
func DefOptOfRefOrder ¶
func DefOptOfRefOrder(check bool, order ...string) DefinitionOption
type Factory ¶
type Factory interface { ContainsObject(name string) bool GetAliases(name string) (aliases []string, err error) GetObject(name string, opts ...Options) (obj interface{}, err error) GetType(name string) (typ reflect.Type) IsPrototype(name string) bool IsSingleton(name string) bool IsTypeMatch(name string, typ reflect.Type) bool Define(name string, scope Scope, model string, opts ...DefinitionOption) error }
func NewClassicFactory ¶
func NewClassicFactory(modelProvider ModelProvider) Factory
type ModelProvider ¶
type ModelProvider interface { Register(model interface{}, aliases ...string) (err error) Get(name string) (typ reflect.Type, exist bool) }
func NewClassicModelProvider ¶
func NewClassicModelProvider() ModelProvider
type NewObjectFunc ¶
type ObjectDefinition ¶
type ObjectDefinition struct {
// contains filtered or unexported fields
}
func (*ObjectDefinition) Aliases ¶
func (p *ObjectDefinition) Aliases() []string
func (*ObjectDefinition) InitialFuncName ¶
func (p *ObjectDefinition) InitialFuncName() string
func (*ObjectDefinition) IsTypeMatch ¶
func (p *ObjectDefinition) IsTypeMatch(typ reflect.Type) bool
func (*ObjectDefinition) Name ¶
func (p *ObjectDefinition) Name() string
func (*ObjectDefinition) NewObjectFunc ¶
func (p *ObjectDefinition) NewObjectFunc() NewObjectFunc
func (*ObjectDefinition) Scope ¶
func (p *ObjectDefinition) Scope() Scope
func (*ObjectDefinition) String ¶
func (p *ObjectDefinition) String() string
func (*ObjectDefinition) Type ¶
func (p *ObjectDefinition) Type() reflect.Type
type ObjectInstance ¶
type ObjectInstance struct {
// contains filtered or unexported fields
}
func (*ObjectInstance) Definition ¶
func (p *ObjectInstance) Definition() ObjectDefinition
func (*ObjectInstance) Id ¶
func (p *ObjectInstance) Id() string
func (*ObjectInstance) Instance ¶
func (p *ObjectInstance) Instance() interface{}
func (*ObjectInstance) Options ¶
func (p *ObjectInstance) Options() Options
func (*ObjectInstance) String ¶
func (p *ObjectInstance) String() string
Source Files
¶
Click to show internal directories.
Click to hide internal directories.