gs_bean

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

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

View Source
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

func NewBean

func NewBean(objOrCtor any, ctorArgs ...gs.Arg) *gs.BeanDefinition

NewBean creates a new bean definition. When registering a normal function, use reflect.ValueOf(fn) to avoid conflicts with constructors.

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) Name

func (d *BeanRuntime) Name() string

Name returns the name 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.

Jump to

Keyboard shortcuts

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