gs

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 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 environment variable prefix。

View Source
const Website = "https://go-spring.dev"

Variables

View Source
View Source
var Version = "v0.0.0"

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.

func WithContext added in v1.1.0

func WithContext(parent context.Context, ctx Context) context.Context

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

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

Configuration scan that the object `i` has `NewXXX` methods to Ioc container.

func (*App) Go

func (app *App) Go(fn func(ctx context.Context))

Go start a goroutine managed by the IoC container.

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 AppConfiguration

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

func NewAppConfiguration

func NewAppConfiguration(resourceLocator ResourceLocator) *AppConfiguration

func (*AppConfiguration) Load

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

type AppEvent

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

AppEvent start and stop events

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 Configuration

func Configuration(i interface{}) *BeanDefinition

Configuration scan the object `i` has `NewXXX` methods 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) Caller

func (d *BeanDefinition) Caller(skip int) *BeanDefinition

Caller update bean register point on source file:line.

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 indicates the types of interface to export.

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.Context) error
}

type BeanSelector

type BeanSelector = utils.BeanSelector

type Container

type Container interface {
	Context() context.Context
	Properties() *dync.Properties
	AllowCircularReferences()
	Object(i interface{}) *BeanDefinition
	Provide(ctor interface{}, args ...arg.Arg) *BeanDefinition
	Configuration(i interface{}) *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.

func FromContext added in v1.1.0

func FromContext(ctx context.Context) Context

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 GetLogOption added in v1.1.0

type GetLogOption func(*logOptions)

func WithLogName added in v1.1.0

func WithLogName(name string) GetLogOption

type Logger

type Logger = log.Logger

func GetLogger

func GetLogger(getOptions ...GetLogOption) *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