Documentation
¶
Overview ¶
Package gs_app provides a framework for building and managing Go-Spring applications.
Index ¶
- type App
- type AppContext
- type AppRunner
- type AppServer
- type Boot
- func (b *Boot) Config() *gs_conf.BootConfig
- func (b *Boot) GroupRegister(fn func(p gs.Properties) ([]*gs.BeanDefinition, error))
- func (b *Boot) Object(i interface{}) *gs.RegisteredBean
- func (b *Boot) Provide(ctor interface{}, args ...gs.Arg) *gs.RegisteredBean
- func (b *Boot) Register(bd *gs.BeanDefinition) *gs.RegisteredBean
- func (b *Boot) Run() error
- func (b *Boot) Runner(objOrCtor interface{}, ctorArgs ...gs.Arg) *gs.RegisteredBean
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
C gs.Container
P *gs_conf.AppConfig
Runners []AppRunner `autowire:"${spring.app.runners:=*?}"`
Servers []AppServer `autowire:"${spring.app.servers:=*?}"`
// contains filtered or unexported fields
}
App represents the core application, managing its lifecycle, configuration, and the injection of dependencies.
func (*App) Run ¶
Run starts the application and listens for termination signals (e.g., SIGINT, SIGTERM). When a signal is received, it shuts down the application gracefully. Use ShutDown but not Stop to end the application lifecycle.
func (*App) ShutDown ¶
ShutDown gracefully terminates the application. It should be used when shutting down the application started by Run.
type AppContext ¶
type AppContext struct {
// contains filtered or unexported fields
}
AppContext provides a wrapper around the application's gs.Context. It offers controlled access to the internal context and is designed to ensure safe usage in the application's lifecycle.
func (*AppContext) Go ¶
func (p *AppContext) Go(fn func(ctx context.Context))
Go executes a function in a new goroutine. The provided function will receive a cancellation signal when the application begins shutting down.
func (*AppContext) Unsafe ¶
func (p *AppContext) Unsafe() gs.Context
Unsafe exposes the underlying gs.Context. Using this method in new goroutines is unsafe because gs.Context may release its resources (e.g., bean definitions), making binding and injection operations invalid.
type AppRunner ¶
type AppRunner interface {
Run(ctx *AppContext)
}
AppRunner defines an interface for tasks that should be executed after all beans are injected but before the application's servers are started. It is commonly used to initialize background jobs or tasks.
type AppServer ¶
type AppServer interface {
OnAppStart(ctx *AppContext)
OnAppStop(ctx context.Context)
}
AppServer defines an interface for managing the lifecycle of application servers, such as HTTP, gRPC, Thrift, or MQ servers. Servers must implement methods for starting and stopping gracefully.
type Boot ¶
type Boot struct {
Runners []AppRunner `autowire:"${spring.boot.runners:=*?}"`
// contains filtered or unexported fields
}
Boot is the bootstrapper of the application.
func (*Boot) Config ¶
func (b *Boot) Config() *gs_conf.BootConfig
Config returns the boot configuration.
func (*Boot) GroupRegister ¶
func (b *Boot) GroupRegister(fn func(p gs.Properties) ([]*gs.BeanDefinition, error))
GroupRegister registers a group of BeanDefinitions.
func (*Boot) Object ¶
func (b *Boot) Object(i interface{}) *gs.RegisteredBean
Object registers an object bean.
func (*Boot) Provide ¶
func (b *Boot) Provide(ctor interface{}, args ...gs.Arg) *gs.RegisteredBean
Provide registers a bean using a constructor function.
func (*Boot) Register ¶
func (b *Boot) Register(bd *gs.BeanDefinition) *gs.RegisteredBean
Register registers a BeanDefinition instance.