gs

package
v1.2.0-alpha Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arg

type Arg interface{}

Arg 用于为函数参数提供绑定值。可以是 bean.Selector 类型,表示注入 bean ; 可以是 ${X:=Y} 形式的字符串,表示属性绑定或者注入 bean ;可以是 ValueArg 类型,表示不从 IoC 容器获取而是用户传入的普通值;可以是 IndexArg 类型,表示 带有下标的参数绑定;可以是 *optionArg 类型,用于为 Option 方法提供参数绑定。

type ArgContext

type ArgContext interface {
	// Matches returns true when the Condition returns true,
	// and returns false when the Condition returns false.
	Matches(c Condition) (bool, error)
	// Bind binds properties value by the "value" tag.
	Bind(v reflect.Value, tag string) error
	// Wire wires dependent beans by the "autowire" tag.
	Wire(v reflect.Value, tag string) error
}

ArgContext defines some methods of IoC container that Callable use.

type BeanRegistration

type BeanRegistration interface {
	ID() string
	Type() reflect.Type
	SetCaller(skip int)
	SetName(name string)
	SetOn(cond Condition)
	SetDependsOn(selectors ...BeanSelector)
	SetPrimary()
	SetInit(fn interface{})
	SetDestroy(fn interface{})
	SetExport(exports ...interface{})
	SetConfiguration(param ...ConfigurationParam)
	SetEnableRefresh(tag string)
}

type BeanSelector

type BeanSelector interface{}

A BeanSelector can be the ID of a bean, a `reflect.Type`, an interface{} pointer such as `(*error)(nil)`, or `new(error)`.

type Callable

type Callable interface {
	Arg(i int) (Arg, bool)
	In(i int) (reflect.Type, bool)
	Call(ctx ArgContext) ([]reflect.Value, error)
}

type CondBean

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

type CondContext

type CondContext interface {
	// Has returns whether the IoC container has a property.
	Has(key string) bool
	// Prop returns the property's value when the IoC container has it, or
	// returns empty string when the IoC container doesn't have it.
	Prop(key string, opts ...conf.GetOption) string
	// Find returns bean definitions that matched with the bean selector.
	Find(selector BeanSelector) ([]CondBean, error)
}

CondContext defines some methods of IoC container that conditions use.

type Condition

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

Condition is used when registering a bean to determine whether it's valid.

type ConfigurationParam

type ConfigurationParam struct {
	Enable  bool     // 是否扫描成员方法
	Include []string // 包含哪些成员方法
	Exclude []string // 排除那些成员方法
}

type Container

type Container interface {
	Object(i interface{}) *RegisteredBean
	Provide(ctor interface{}, args ...Arg) *RegisteredBean
	Accept(b *UnregisteredBean) *RegisteredBean
	Group(fn func(p Properties) ([]*UnregisteredBean, error))
	RefreshProperties(p Properties) error
	Refresh() error
	SimplifyMemory()
	Close()
}

Container ...

type Context

type Context interface {
	Context() context.Context
	Keys() []string
	Has(key string) bool
	SubKeys(key string) ([]string, error)
	Prop(key string, opts ...conf.GetOption) string
	Resolve(s string) (string, error)
	Bind(i interface{}, opts ...conf.BindArg) error
	Get(i interface{}, selectors ...BeanSelector) error
	Wire(objOrCtor interface{}, ctorArgs ...Arg) (interface{}, error)
	Invoke(fn interface{}, args ...Arg) ([]interface{}, error)
	Go(fn func(ctx context.Context))
}

Context ...

type ContextAware

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

ContextAware injects the Context into a struct as the field GSContext.

type Properties

type Properties interface {
	Data() map[string]string
	Keys() []string
	Has(key string) bool
	SubKeys(key string) ([]string, error)
	Get(key string, opts ...conf.GetOption) string
	Resolve(s string) (string, error)
	Bind(i interface{}, args ...conf.BindArg) error
	CopyTo(out *conf.Properties) error
}

type Refreshable

type Refreshable interface {
	OnRefresh(prop Properties, param conf.BindParam) error
}

Refreshable 可动态刷新的对象

type RegisteredBean

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

func NewRegisteredBean

func NewRegisteredBean(d BeanRegistration) *RegisteredBean

func (*RegisteredBean) BeanRegistration

func (d *RegisteredBean) BeanRegistration() BeanRegistration

func (*RegisteredBean) Configuration

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

Configuration 设置 bean 为配置类。

func (*RegisteredBean) DependsOn

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

DependsOn 设置 bean 的间接依赖项。

func (*RegisteredBean) Destroy

func (d *RegisteredBean) Destroy(fn interface{}) *T

Destroy 设置 bean 的销毁函数。

func (*RegisteredBean) EnableRefresh

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

EnableRefresh 设置 bean 为可刷新的。

func (*RegisteredBean) Export

func (d *RegisteredBean) Export(exports ...interface{}) *T

Export 设置 bean 的导出接口。

func (*RegisteredBean) ID

func (d *RegisteredBean) ID() string

func (*RegisteredBean) Init

func (d *RegisteredBean) Init(fn interface{}) *T

Init 设置 bean 的初始化函数。

func (*RegisteredBean) Name

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

func (*RegisteredBean) On

func (d *RegisteredBean) On(cond Condition) *T

On 设置 bean 的 Condition。

func (*RegisteredBean) Primary

func (d *RegisteredBean) Primary() *T

Primary 设置 bean 为主版本。

func (*RegisteredBean) Type

func (d *RegisteredBean) Type() reflect.Type

type UnregisteredBean

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

func NewUnregisteredBean

func NewUnregisteredBean(d BeanRegistration) *UnregisteredBean

func (*UnregisteredBean) BeanRegistration

func (d *UnregisteredBean) BeanRegistration() BeanRegistration

func (*UnregisteredBean) Configuration

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

Configuration 设置 bean 为配置类。

func (*UnregisteredBean) DependsOn

func (d *UnregisteredBean) DependsOn(selectors ...BeanSelector) *T

DependsOn 设置 bean 的间接依赖项。

func (*UnregisteredBean) Destroy

func (d *UnregisteredBean) Destroy(fn interface{}) *T

Destroy 设置 bean 的销毁函数。

func (*UnregisteredBean) EnableRefresh

func (d *UnregisteredBean) EnableRefresh(tag string) *T

EnableRefresh 设置 bean 为可刷新的。

func (*UnregisteredBean) Export

func (d *UnregisteredBean) Export(exports ...interface{}) *T

Export 设置 bean 的导出接口。

func (*UnregisteredBean) ID

func (d *UnregisteredBean) ID() string

func (*UnregisteredBean) Init

func (d *UnregisteredBean) Init(fn interface{}) *T

Init 设置 bean 的初始化函数。

func (*UnregisteredBean) Name

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

func (*UnregisteredBean) On

func (d *UnregisteredBean) On(cond Condition) *T

On 设置 bean 的 Condition。

func (*UnregisteredBean) Primary

func (d *UnregisteredBean) Primary() *T

Primary 设置 bean 为主版本。

func (*UnregisteredBean) Type

func (d *UnregisteredBean) Type() reflect.Type

Jump to

Keyboard shortcuts

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