Documentation
¶
Overview ¶
Package gs is a core of Go-Spring, including IOC container, IOC container-based APP.
Index ¶
- Constants
- Variables
- func AllowCircularReferences()
- func BeanID(typ interface{}, name string) string
- func Go(fn func(ctx context.Context))
- func OnProperty(key string, fn interface{})
- func Property(key string, fn interface{})
- func Run(resourceLocator ...ResourceLocator) error
- func SetLogger(loggerName string, logger *Logger, primary ...bool)
- func Setenv(key string, value string)
- func Shutdown(msg ...string)
- func WithContext(parent context.Context, ctx Context) context.Context
- type App
- func (app *App) Accept(b *BeanDefinition) *BeanDefinition
- func (app *App) AllowCircularReferences()
- func (app *App) Configuration(i interface{}) *BeanDefinition
- func (app *App) Go(fn func(ctx context.Context))
- func (app *App) Object(i interface{}) *BeanDefinition
- func (app *App) OnProperty(key string, fn interface{})
- func (app *App) Property(key string, value interface{})
- func (app *App) Provide(ctor interface{}, args ...arg.Arg) *BeanDefinition
- func (app *App) Run(resourceLocator ...ResourceLocator) error
- func (app *App) Shutdown(msg ...string)
- type AppConfiguration
- type AppEvent
- type BeanDefinition
- func (d *BeanDefinition) BeanName() string
- func (d *BeanDefinition) Caller(skip int) *BeanDefinition
- func (d *BeanDefinition) Created() bool
- func (d *BeanDefinition) DependsOn(selectors ...BeanSelector) *BeanDefinition
- func (d *BeanDefinition) Destroy(fn interface{}) *BeanDefinition
- func (d *BeanDefinition) Export(exports ...interface{}) *BeanDefinition
- func (d *BeanDefinition) FileLine() string
- func (d *BeanDefinition) ID() string
- func (d *BeanDefinition) Init(fn interface{}) *BeanDefinition
- func (d *BeanDefinition) Interface() interface{}
- func (d *BeanDefinition) Match(typeName string, beanName string) bool
- func (d *BeanDefinition) Name(name string) *BeanDefinition
- func (d *BeanDefinition) On(c cond.Condition) *BeanDefinition
- func (d *BeanDefinition) Order(order float32) *BeanDefinition
- func (d *BeanDefinition) Primary() *BeanDefinition
- func (d *BeanDefinition) String() string
- func (d *BeanDefinition) Type() reflect.Type
- func (d *BeanDefinition) TypeName() string
- func (d *BeanDefinition) Value() reflect.Value
- func (d *BeanDefinition) Wired() bool
- type BeanDestroy
- type BeanInit
- type BeanSelector
- type Container
- type Context
- type FileResourceLocator
- type GetLogOption
- type Logger
- type Resource
- type ResourceLocator
Constants ¶
const ( Unrefreshed = refreshState(iota) RefreshInit Refreshing Refreshed )
const ( Deleted = beanStatus(-1) Default = beanStatus(iota) Resolving Resolved Creating Created Wired )
const EnvPrefix = "GS_"
EnvPrefix environment variable prefix。
const Website = "https://go-spring.dev"
Variables ¶
var Banner = `` /* 199-byte string literal not displayed */
var Version = "v0.0.0"
Functions ¶
func AllowCircularReferences ¶
func AllowCircularReferences()
AllowCircularReferences enable circular-references.
func OnProperty ¶
func OnProperty(key string, fn interface{})
OnProperty binding a callback when the property key loaded.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App Ioc 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) Object ¶
func (app *App) Object(i interface{}) *BeanDefinition
Object register object bean to Ioc container.
func (*App) OnProperty ¶
OnProperty binding a callback when the property key loaded.
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 BeanDefinition ¶
type BeanDefinition struct {
// contains filtered or unexported fields
}
BeanDefinition bean.
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 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) 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 ¶
func (d *BeanDefinition) On(c cond.Condition) *BeanDefinition
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 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() }
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
type FileResourceLocator ¶
type FileResourceLocator struct {
ConfigLocations []string `value:"${spring.config.locations:=config/}"`
}
FileResourceLocator locate Resource from file system.
type GetLogOption ¶ added in v1.1.0
type GetLogOption func(*logOptions)
func WithLogName ¶ added in v1.1.0
func WithLogName(name string) GetLogOption
type Resource ¶
type Resource interface { io.ReadCloser Name() string }