gs

package
v0.0.0-...-bd77e7c Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package gs is a core of Go-Spring, including IOC container, IOC container-based APP.

Index

Constants

View Source
const (
	Unrefreshed = refreshState(iota)
	RefreshInit
	Refreshing
	Refreshed
)
View Source
const (
	Deleted = beanStatus(-1)
	Default = beanStatus(iota)
	Resolving
	Resolved
	Creating
	Created
	Wired
)
View Source
const EnvPrefix = "GS_"

EnvPrefix 属性覆盖的环境变量需要携带该前缀。

View Source
const Website = "https://github.com/limpo1989/go-spring"

Variables

View Source
View Source
var Version = "go-spring"

Functions

func AllowCircularReferences

func AllowCircularReferences()

AllowCircularReferences enable circular-references.

func BeanID

func BeanID(typ interface{}, name string) string

func Go

func Go(fn func(ctx context.Context))

Go start a goroutine managed by the IoC container.

func OnProperty

func OnProperty(key string, fn interface{})

OnProperty binding a callback when the property key loaded.

func Property

func Property(key string, fn interface{})

Property set property key/value.

func Run

func Run(resourceLocator ...ResourceLocator) error

Run start boot app.

func SetLogger

func SetLogger(loggerName string, logger *Logger, primary ...bool)

func Setenv

func Setenv(key string, value string)

Setenv convert property syntax to env.

func Shutdown

func Shutdown(msg ...string)

Shutdown close boot app.

Types

type App

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

App Ioc App

func NewApp

func NewApp() *App

NewApp make a new App

func (*App) Accept

func (app *App) Accept(b *BeanDefinition) *BeanDefinition

Accept register bean to Ioc container.

func (*App) AllowCircularReferences

func (app *App) AllowCircularReferences()

AllowCircularReferences enable circular-references.

func (*App) Object

func (app *App) Object(i interface{}) *BeanDefinition

Object register object bean to Ioc container.

func (*App) OnProperty

func (app *App) OnProperty(key string, fn interface{})

OnProperty binding a callback when the property key loaded.

func (*App) Property

func (app *App) Property(key string, value interface{})

Property set property key/value

func (*App) Provide

func (app *App) Provide(ctor interface{}, args ...arg.Arg) *BeanDefinition

Provide register method bean to Ioc container.

func (*App) Run

func (app *App) Run(resourceLocator ...ResourceLocator) error

Run start app.

func (*App) Shutdown

func (app *App) Shutdown(msg ...string)

Shutdown close application.

type AppEvent

type AppEvent interface {
	OnAppStart(ctx Context)
	OnAppStop(ctx context.Context)
}

AppEvent start and stop events

type AppRunner

type AppRunner interface {
	Run(ctx Context)
}

AppRunner .

type BeanDefinition

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

BeanDefinition bean.

func Accept

func Accept(b *BeanDefinition) *BeanDefinition

Accept register bean to Ioc container.

func NewBean

func NewBean(objOrCtor interface{}, ctorArgs ...arg.Arg) *BeanDefinition

NewBean create bean from object or function. When registering a regular function, use the form reflect.ValueOf(fn) to avoid conflicts with constructor functions.

func Object

func Object(i interface{}) *BeanDefinition

Object register bean to Ioc container.

func Provide

func Provide(ctor interface{}, args ...arg.Arg) *BeanDefinition

Provide register bean to Ioc container.

func (*BeanDefinition) BeanName

func (d *BeanDefinition) BeanName() string

BeanName Return the name of the bean.

func (*BeanDefinition) Created

func (d *BeanDefinition) Created() bool

Created Return whether the bean has been created or not.

func (*BeanDefinition) DependsOn

func (d *BeanDefinition) DependsOn(selectors ...BeanSelector) *BeanDefinition

DependsOn Set the indirect dependencies for a bean.

func (*BeanDefinition) Destroy

func (d *BeanDefinition) Destroy(fn interface{}) *BeanDefinition

Destroy Set the destruction function for a bean.

func (*BeanDefinition) Export

func (d *BeanDefinition) Export(exports ...interface{}) *BeanDefinition

Export 设置 bean 的导出接口。

func (*BeanDefinition) FileLine

func (d *BeanDefinition) FileLine() string

FileLine Return the registration file:line of a bean.

func (*BeanDefinition) ID

func (d *BeanDefinition) ID() string

ID Return the ID of the bean.

func (*BeanDefinition) Init

func (d *BeanDefinition) Init(fn interface{}) *BeanDefinition

Init Set the initialization function for a bean.

func (*BeanDefinition) Interface

func (d *BeanDefinition) Interface() interface{}

Interface Return the actual value of the bean.

func (*BeanDefinition) Match

func (d *BeanDefinition) Match(typeName string, beanName string) bool

Match Test if the fully qualified name of a bean's type and its name both match.

func (*BeanDefinition) Name

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

Name Set the bean name.

func (*BeanDefinition) On

On Set the condition for a bean.

func (*BeanDefinition) Order

func (d *BeanDefinition) Order(order float32) *BeanDefinition

Order Set the sorting order for a bean, where a smaller value indicates a higher priority or an earlier position in the order.

func (*BeanDefinition) Primary

func (d *BeanDefinition) Primary() *BeanDefinition

Primary mark primary.

func (*BeanDefinition) String

func (d *BeanDefinition) String() string

func (*BeanDefinition) Type

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

Type Return the type of the bean.

func (*BeanDefinition) TypeName

func (d *BeanDefinition) TypeName() string

TypeName Return the fully qualified name of the bean's original type.

func (*BeanDefinition) Value

func (d *BeanDefinition) Value() reflect.Value

Value Return the value of the bean.

func (*BeanDefinition) Wired

func (d *BeanDefinition) Wired() bool

Wired Return whether the bean has been injected or not.

type BeanDestroy

type BeanDestroy interface {
	OnDestroy()
}

type BeanInit

type BeanInit interface {
	OnInit(ctx Context) error
}

type BeanSelector

type BeanSelector = utils.BeanSelector

type Configuration

type Configuration struct {
	ActiveProfiles   []string `value:"${spring.config.profiles:=}"`
	ConfigExtensions []string `value:"${spring.config.extensions:=.properties,.yaml,.yml,.toml,.tml}"`
	// contains filtered or unexported fields
}

func NewConfiguration

func NewConfiguration(resourceLocator ResourceLocator) *Configuration

func (*Configuration) Load

func (e *Configuration) Load(props *conf.Properties) error

type Container

type Container interface {
	Context() context.Context
	Properties() *dync.Properties
	AllowCircularReferences()
	Object(i interface{}) *BeanDefinition
	Provide(ctor interface{}, args ...arg.Arg) *BeanDefinition
	Refresh() error
	Close()
}

func New

func New() Container

New make a IoC container.

type Context

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

Context provides interfaces for using properties and beans based on reflection after the IoC container is started.

type ContextAware

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

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

type FileResourceLocator

type FileResourceLocator struct {
	ConfigLocations []string `value:"${spring.config.locations:=config/}"`
}

FileResourceLocator locate Resource from file system.

func (*FileResourceLocator) Locate

func (locator *FileResourceLocator) Locate(filename string) ([]Resource, error)

type Logger

type Logger = log.Logger

func GetLogger

func GetLogger(loggerName string, typeName string) *Logger

type Resource

type Resource interface {
	io.ReadCloser
	Name() string
}

type ResourceLocator

type ResourceLocator interface {
	Locate(filename string) ([]Resource, error)
}

Directories

Path Synopsis
Package arg provide a method arguments binding。
Package arg provide a method arguments binding。
Package cond provides many conditions used when registering bean.
Package cond provides many conditions used when registering bean.

Jump to

Keyboard shortcuts

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