gs

package
v1.2.0-rc Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package gs provides all the concepts required for Go-Spring implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arg

type Arg interface {
	GetArgValue(ctx ArgContext, t reflect.Type) (reflect.Value, error)
}

Arg is used to provide binding values for function parameters.

type ArgContext

type ArgContext interface {
	// Matches checks if the given condition is met.
	Matches(c Condition) (bool, error)
	// Bind binds property values to the provided [reflect.Value].
	Bind(v reflect.Value, tag string) error
	// Wire wires dependent beans to the provided [reflect.Value].
	Wire(v reflect.Value, tag string) error
}

ArgContext defines methods for the IoC container used by Callable types.

type BeanDefinition

type BeanDefinition struct {
	// contains filtered or unexported fields
}

BeanDefinition represents a bean that has not yet been registered in the IoC container.

func NewBeanDefinition

func NewBeanDefinition(d BeanRegistration) *BeanDefinition

NewBeanDefinition creates a new BeanDefinition instance.

func (*BeanDefinition) BeanRegistration

func (d *BeanDefinition) BeanRegistration() BeanRegistration

BeanRegistration returns the underlying BeanRegistration instance.

func (*BeanDefinition) Condition

func (d *BeanDefinition) Condition(conditions ...Condition) *T

Condition adds a condition to validate the bean.

func (*BeanDefinition) Configuration

func (d *BeanDefinition) Configuration(param ...ConfigurationParam) *T

Configuration applies the configuration parameters to the bean.

func (*BeanDefinition) DependsOn

func (d *BeanDefinition) DependsOn(selectors ...BeanSelectorInterface) *T

DependsOn sets the beans that this bean depends on.

func (*BeanDefinition) Destroy

func (d *BeanDefinition) Destroy(fn BeanDestroyFunc) *T

Destroy sets the destruction function for the bean.

func (*BeanDefinition) Export

func (d *BeanDefinition) Export(exports ...reflect.Type) *T

Export sets the interfaces that the bean will export.

func (*BeanDefinition) GetArgValue

func (d *BeanDefinition) GetArgValue(ctx ArgContext, t reflect.Type) (reflect.Value, error)

GetArgValue returns the value of the bean.

func (*BeanDefinition) Init

func (d *BeanDefinition) Init(fn BeanInitFunc) *T

Init sets the initialization function for the bean.

func (*BeanDefinition) Name

func (d *BeanDefinition) Name(name string) *T

Name sets the name of the bean.

func (*BeanDefinition) Refreshable

func (d *BeanDefinition) Refreshable(tag string) *T

Refreshable marks the bean as refreshable with the provided tag.

func (*BeanDefinition) TypeAndName

func (d *BeanDefinition) TypeAndName() (reflect.Type, string)

TypeAndName returns the type and name of the bean.

type BeanDestroyFunc

type BeanDestroyFunc = interface{}

BeanDestroyFunc defines the prototype for destroy functions. For example: `func(bean)` or `func(bean) error`.

type BeanDestroyInterface

type BeanDestroyInterface interface {
	OnBeanDestroy()
}

BeanDestroyInterface defines an interface for bean destruction.

type BeanInitFunc

type BeanInitFunc = interface{}

BeanInitFunc defines the prototype for initialization functions. For example: `func(bean)` or `func(bean) error`.

type BeanInitInterface

type BeanInitInterface interface {
	OnBeanInit(ctx Context) error
}

BeanInitInterface defines an interface for bean initialization.

type BeanRegistration

type BeanRegistration interface {
	// Name returns the name of the bean.
	Name() string
	// Type returns the [reflect.Type] of the bean.
	Type() reflect.Type
	// Value returns the [reflect.Value] of the bean.
	Value() reflect.Value
	// SetName sets the name of the bean.
	SetName(name string)
	// SetInit sets the initialization function for the bean.
	SetInit(fn BeanInitFunc)
	// SetDestroy sets the destruction function for the bean.
	SetDestroy(fn BeanDestroyFunc)
	// SetCondition adds a condition for the bean.
	SetCondition(conditions ...Condition)
	// SetDependsOn sets the beans that this bean depends on.
	SetDependsOn(selectors ...BeanSelectorInterface)
	// SetExport defines the interfaces to be exported by the bean.
	SetExport(exports ...reflect.Type)
	// SetConfiguration applies the bean configuration.
	SetConfiguration(param ...ConfigurationParam)
	// SetRefreshable marks the bean as refreshable with the given tag.
	SetRefreshable(tag string)
}

BeanRegistration provides methods to configure and register bean metadata.

type BeanSelector

type BeanSelector struct {
	Type reflect.Type // Type of the bean
	Name string       // Name of the bean
}

BeanSelector is an identifier for a bean.

func BeanSelectorForType

func BeanSelectorForType[T any]() BeanSelector

BeanSelectorForType returns a BeanSelector for the given type.

func (BeanSelector) String

func (s BeanSelector) String() string

func (BeanSelector) TypeAndName

func (s BeanSelector) TypeAndName() (reflect.Type, string)

TypeAndName returns the type and name of the bean.

type BeanSelectorInterface

type BeanSelectorInterface interface {
	TypeAndName() (reflect.Type, string)
}

BeanSelectorInterface is an interface for selecting beans.

type Callable

type Callable interface {
	Call(ctx ArgContext) ([]reflect.Value, error)
}

Callable represents an entity that can be invoked with an ArgContext.

type CondBean

type CondBean interface {
	Name() string
	Type() reflect.Type
}

CondBean represents a bean with Name and Type.

type CondContext

type CondContext interface {
	// Has checks whether the IoC container has a property with the given key.
	Has(key string) bool
	// Prop retrieves the value of a property from the IoC container.
	Prop(key string, def ...string) string
	// Find searches for bean definitions that match the provided BeanSelector.
	Find(s BeanSelectorInterface) ([]CondBean, error)
}

CondContext defines methods for the IoC container used by conditions.

type CondFunc

type CondFunc func(ctx CondContext) (bool, error)

CondFunc is a function type that determines whether a condition is satisfied.

type Condition

type Condition interface {
	Matches(ctx CondContext) (bool, error)
}

Condition is a conditional logic interface used when registering beans.

type ConfigurationParam

type ConfigurationParam struct {
	Includes []string // List of methods to include
	Excludes []string // List of methods to exclude
}

ConfigurationParam holds configuration parameters for bean setup.

type Container

type Container interface {
	// Object registers a bean using the provided object instance.
	Object(i interface{}) *RegisteredBean
	// Provide registers a bean using the provided constructor function and optional arguments.
	Provide(ctor interface{}, args ...Arg) *RegisteredBean
	// Register registers a bean using the provided bean definition.
	Register(b *BeanDefinition) *RegisteredBean
	// GroupRegister registers multiple beans by executing the given function that returns [*BeanDefinition]s.
	GroupRegister(fn func(p Properties) ([]*BeanDefinition, error))
	// RefreshProperties updates the properties of the container.
	RefreshProperties(p Properties) error
	// Refresh initializes and wires all beans in the container.
	Refresh() error
	// ReleaseUnusedMemory cleans up unused resources and releases memory.
	ReleaseUnusedMemory()
	// Close shuts down the container and cleans up all resources.
	Close()
}

Container represents the modifiable aspects of an IoC (Inversion of Control) container. It provides methods for registering, refreshing, and managing beans within the container.

type Context

type Context interface {
	// Keys returns all the keys present in the container's properties.
	Keys() []string
	// Has checks if the specified key exists in the container's properties.
	Has(key string) bool
	// SubKeys returns the sub-keys under a specific key in the container's properties.
	SubKeys(key string) ([]string, error)
	// Prop retrieves the value of the specified key from the container's properties.
	Prop(key string, def ...string) string
	// Resolve resolves placeholders or references (e.g., ${KEY}) in the given string to actual values.
	Resolve(s string) (string, error)
	// Bind binds the value of the specified key to the provided struct or variable.
	Bind(i interface{}, tag ...string) error
	// Get retrieves a bean of the specified type using the provided tag.
	Get(i interface{}, tag ...string) error
	// Wire creates and returns a bean by wiring it with the provided constructor or object.
	Wire(objOrCtor interface{}, ctorArgs ...Arg) (interface{}, error)
	// Invoke calls the provided function with the specified arguments and returns the result.
	Invoke(fn interface{}, args ...Arg) ([]interface{}, error)
}

Context represents the unmodifiable (or runtime) aspects of an IoC container. It provides methods for accessing properties, resolving values, and retrieving beans.

type ContextAware

type ContextAware struct {
	GSContext Context `autowire:""`
}

ContextAware is used to inject the container's Context into a bean.

type Properties

type Properties = conf.ReadOnlyProperties

Properties represents read-only configuration properties.

type Refreshable

type Refreshable interface {
	// OnRefresh is called to refresh the properties when they change.
	OnRefresh(prop Properties, param conf.BindParam) error
}

Refreshable represents an object that can be dynamically refreshed.

type RegisteredBean

type RegisteredBean struct {
	// contains filtered or unexported fields
}

RegisteredBean represents a bean that has been registered in the IoC container.

func NewRegisteredBean

func NewRegisteredBean(d BeanRegistration) *RegisteredBean

NewRegisteredBean creates a new RegisteredBean instance.

func (*RegisteredBean) BeanRegistration

func (d *RegisteredBean) BeanRegistration() BeanRegistration

BeanRegistration returns the underlying BeanRegistration instance.

func (*RegisteredBean) Condition

func (d *RegisteredBean) Condition(conditions ...Condition) *T

Condition adds a condition to validate the bean.

func (*RegisteredBean) Configuration

func (d *RegisteredBean) Configuration(param ...ConfigurationParam) *T

Configuration applies the configuration parameters to the bean.

func (*RegisteredBean) DependsOn

func (d *RegisteredBean) DependsOn(selectors ...BeanSelectorInterface) *T

DependsOn sets the beans that this bean depends on.

func (*RegisteredBean) Destroy

func (d *RegisteredBean) Destroy(fn BeanDestroyFunc) *T

Destroy sets the destruction function for the bean.

func (*RegisteredBean) Export

func (d *RegisteredBean) Export(exports ...reflect.Type) *T

Export sets the interfaces that the bean will export.

func (*RegisteredBean) GetArgValue

func (d *RegisteredBean) GetArgValue(ctx ArgContext, t reflect.Type) (reflect.Value, error)

GetArgValue returns the value of the bean.

func (*RegisteredBean) Init

func (d *RegisteredBean) Init(fn BeanInitFunc) *T

Init sets the initialization function for the bean.

func (*RegisteredBean) Name

func (d *RegisteredBean) Name(name string) *T

Name sets the name of the bean.

func (*RegisteredBean) Refreshable

func (d *RegisteredBean) Refreshable(tag string) *T

Refreshable marks the bean as refreshable with the provided tag.

func (*RegisteredBean) TypeAndName

func (d *RegisteredBean) TypeAndName() (reflect.Type, string)

TypeAndName returns the type and name of the bean.

Jump to

Keyboard shortcuts

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