Documentation
¶
Overview ¶
Package gs_bean provides core bean management for Go-Spring framework, featuring:
- Full lifecycle management (instantiation, DI, destruction)
- Method-as-factory mechanism (generate child beans via configured rules)
- Conditional registration (profile-based activation)
- Type-safe interface export validation
- Mock replacement mechanism
Index ¶
- Constants
- func NewBean(objOrCtor any, ctorArgs ...gs.Arg) *gs.BeanDefinition
- type BeanDefinition
- func (d *BeanDefinition) Callable() *gs_arg.Callable
- func (d *BeanDefinition) OnProfiles(profiles string)
- func (d *BeanDefinition) SetConfiguration(c ...gs.Configuration)
- func (d *BeanDefinition) SetDestroy(fn gs.BeanDestroyFunc)
- func (d *BeanDefinition) SetDestroyMethod(method string)
- func (d *BeanDefinition) SetExport(exports ...reflect.Type)
- func (d *BeanDefinition) SetInit(fn gs.BeanInitFunc)
- func (d *BeanDefinition) SetInitMethod(method string)
- func (d *BeanDefinition) SetMock(obj any)
- func (d *BeanDefinition) SetName(name string)
- func (d *BeanDefinition) SetStatus(status BeanStatus)
- func (d *BeanDefinition) Status() BeanStatus
- func (d *BeanDefinition) String() string
- func (d *BeanDefinition) TypeAndName() (reflect.Type, string)
- type BeanMetadata
- func (d *BeanMetadata) Conditions() []gs.Condition
- func (d *BeanMetadata) Configuration() *gs.Configuration
- func (d *BeanMetadata) DependsOn() []gs.BeanSelector
- func (d *BeanMetadata) Destroy() gs.BeanDestroyFunc
- func (d *BeanMetadata) Exports() []reflect.Type
- func (d *BeanMetadata) FileLine() string
- func (d *BeanMetadata) Init() gs.BeanInitFunc
- func (d *BeanMetadata) Mocked() bool
- func (d *BeanMetadata) SetCaller(skip int)
- func (d *BeanMetadata) SetCondition(conditions ...gs.Condition)
- func (d *BeanMetadata) SetDependsOn(selectors ...gs.BeanSelector)
- func (d *BeanMetadata) SetFileLine(file string, line int)
- type BeanRuntime
- type BeanStatus
Constants ¶
const ( StatusDeleted = BeanStatus(-1) // Bean has been deleted. StatusDefault = BeanStatus(iota) // Default status of the bean. StatusResolving // Bean is being resolved. StatusResolved // Bean has been resolved. StatusCreating // Bean is being created. StatusCreated // Bean has been created. StatusWired // Bean has been wired. )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BeanDefinition ¶
type BeanDefinition struct { *BeanMetadata *BeanRuntime }
BeanDefinition contains both metadata and runtime information of a bean.
func (*BeanDefinition) Callable ¶
func (d *BeanDefinition) Callable() *gs_arg.Callable
Callable returns the callable for the bean.
func (*BeanDefinition) OnProfiles ¶
func (d *BeanDefinition) OnProfiles(profiles string)
OnProfiles sets the conditions for the bean based on the active profiles.
func (*BeanDefinition) SetConfiguration ¶
func (d *BeanDefinition) SetConfiguration(c ...gs.Configuration)
SetConfiguration sets the configuration flag and parameters for the bean.
func (*BeanDefinition) SetDestroy ¶
func (d *BeanDefinition) SetDestroy(fn gs.BeanDestroyFunc)
SetDestroy sets the destruction function for the bean.
func (*BeanDefinition) SetDestroyMethod ¶
func (d *BeanDefinition) SetDestroyMethod(method string)
SetDestroyMethod sets the destruction function for the bean by method name.
func (*BeanDefinition) SetExport ¶
func (d *BeanDefinition) SetExport(exports ...reflect.Type)
SetExport sets the exported interfaces for the bean.
func (*BeanDefinition) SetInit ¶
func (d *BeanDefinition) SetInit(fn gs.BeanInitFunc)
SetInit sets the initialization function for the bean.
func (*BeanDefinition) SetInitMethod ¶
func (d *BeanDefinition) SetInitMethod(method string)
SetInitMethod sets the initialization function for the bean by method name.
func (*BeanDefinition) SetMock ¶
func (d *BeanDefinition) SetMock(obj any)
SetMock sets the mock object for the bean, replacing its runtime information.
func (*BeanDefinition) SetName ¶
func (d *BeanDefinition) SetName(name string)
SetName sets the name of the bean.
func (*BeanDefinition) SetStatus ¶
func (d *BeanDefinition) SetStatus(status BeanStatus)
SetStatus sets the current status of the bean.
func (*BeanDefinition) Status ¶
func (d *BeanDefinition) Status() BeanStatus
Status returns the current status of the bean.
func (*BeanDefinition) String ¶
func (d *BeanDefinition) String() string
String returns a string representation of the bean.
func (*BeanDefinition) TypeAndName ¶
func (d *BeanDefinition) TypeAndName() (reflect.Type, string)
TypeAndName returns the type and name of the bean.
type BeanMetadata ¶
type BeanMetadata struct {
// contains filtered or unexported fields
}
BeanMetadata holds the metadata information of a bean.
func (*BeanMetadata) Conditions ¶
func (d *BeanMetadata) Conditions() []gs.Condition
Conditions returns the list of conditions for the bean.
func (*BeanMetadata) Configuration ¶
func (d *BeanMetadata) Configuration() *gs.Configuration
Configuration returns the configuration parameters for the bean.
func (*BeanMetadata) DependsOn ¶
func (d *BeanMetadata) DependsOn() []gs.BeanSelector
DependsOn returns the list of dependencies for the bean.
func (*BeanMetadata) Destroy ¶
func (d *BeanMetadata) Destroy() gs.BeanDestroyFunc
Destroy returns the destruction function of the bean.
func (*BeanMetadata) Exports ¶
func (d *BeanMetadata) Exports() []reflect.Type
Exports returns the list of exported types for the bean.
func (*BeanMetadata) FileLine ¶
func (d *BeanMetadata) FileLine() string
FileLine returns the file and line number for the bean.
func (*BeanMetadata) Init ¶
func (d *BeanMetadata) Init() gs.BeanInitFunc
Init returns the initialization function of the bean.
func (*BeanMetadata) Mocked ¶
func (d *BeanMetadata) Mocked() bool
Mocked returns true if the bean is mocked.
func (*BeanMetadata) SetCaller ¶
func (d *BeanMetadata) SetCaller(skip int)
SetCaller sets the caller for the bean.
func (*BeanMetadata) SetCondition ¶
func (d *BeanMetadata) SetCondition(conditions ...gs.Condition)
SetCondition adds a condition to the list of conditions for the bean.
func (*BeanMetadata) SetDependsOn ¶
func (d *BeanMetadata) SetDependsOn(selectors ...gs.BeanSelector)
SetDependsOn sets the list of dependencies for the bean.
func (*BeanMetadata) SetFileLine ¶
func (d *BeanMetadata) SetFileLine(file string, line int)
SetFileLine sets the file and line number for the bean.
type BeanRuntime ¶
type BeanRuntime struct {
// contains filtered or unexported fields
}
BeanRuntime holds runtime information about the bean.
func (*BeanRuntime) Callable ¶
func (d *BeanRuntime) Callable() *gs_arg.Callable
Callable returns the callable for the bean.
func (*BeanRuntime) Interface ¶
func (d *BeanRuntime) Interface() any
Interface returns the underlying value of the bean.
func (*BeanRuntime) Status ¶
func (d *BeanRuntime) Status() BeanStatus
Status returns the current status of the bean.
func (*BeanRuntime) String ¶
func (d *BeanRuntime) String() string
String returns a string representation of the bean.
func (*BeanRuntime) Type ¶
func (d *BeanRuntime) Type() reflect.Type
Type returns the type of the bean.
func (*BeanRuntime) Value ¶
func (d *BeanRuntime) Value() reflect.Value
Value returns the value of the bean as reflect.Value.
type BeanStatus ¶
type BeanStatus int8
BeanStatus represents the different lifecycle statuses of a bean.
func (BeanStatus) String ¶
func (status BeanStatus) String() string
String returns a human-readable string of the bean status.