Documentation
¶
Index ¶
- type App
- func (app *App) Context() context.Context
- func (app *App) Exiting() bool
- func (app *App) Property(key string, val string)
- func (app *App) Provide(objOrCtor any, args ...gs.Arg) *gs_bean.BeanDefinition
- func (app *App) RefreshProperties() error
- func (app *App) ShutDown()
- func (app *App) Start() error
- func (app *App) WaitForShutdown()
- type ConfigRefresher
- type ContextAware
- type ReadySignal
- type ReadySignalImpl
- type Runner
- type Server
- type ServerMockImpl
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
Runners []Runner `autowire:"${spring.app.runners:=?}"`
Servers []Server `autowire:"${spring.app.servers:=?}"`
// contains filtered or unexported fields
}
App represents the core application, managing its lifecycle, configuration, and dependency injection.
func NewApp ¶
func NewApp() *App
NewApp creates a new App instance with an initialized root context.
func (*App) Property ¶ added in v1.3.0
Property sets an app-level property in the application's configuration. It associates the property with the caller file for traceability.
func (*App) Provide ¶ added in v1.3.0
Provide registers a new bean definition in the IoC container. The parameter can be either an existing instance or a constructor function. Additional arguments can be passed for dependency injection.
func (*App) RefreshProperties ¶ added in v1.3.0
RefreshProperties reloads application properties from all sources and propagates the changes to the IoC container.
func (*App) ShutDown ¶
func (app *App) ShutDown()
ShutDown initiates a graceful shutdown of the application. It sets the exiting flag and cancels the root context.
func (*App) Start ¶
Start initializes and launches the application. The startup sequence is:
- Initialize logging
- Register ContextAware and App beans
- Load configuration and refresh the container
- Execute all Runner beans
- Launch all servers in separate goroutines
- Wait for readiness signal from all servers
func (*App) WaitForShutdown ¶ added in v1.2.4
func (app *App) WaitForShutdown()
WaitForShutdown blocks until the application is signaled to shut down. It then gracefully stops all servers.
type ConfigRefresher ¶
type ConfigRefresher struct {
// contains filtered or unexported fields
}
ConfigRefresher is an interface for components that need to refresh application properties after configuration changes.
func (*ConfigRefresher) RefreshProperties ¶
func (c *ConfigRefresher) RefreshProperties() error
RefreshProperties refreshes application properties and propagates the changes to the IoC container.
type ContextAware ¶
ContextAware provides access to the application's root context. Users can inject this bean to access the App's context.
type ReadySignal ¶
type ReadySignal interface {
TriggerAndWait() <-chan struct{}
}
ReadySignal defines an interface for signaling application readiness. Servers can use this to indicate when they are ready to accept requests.
type ReadySignalImpl ¶ added in v1.3.0
type ReadySignalImpl struct {
// contains filtered or unexported fields
}
ReadySignalImpl is a synchronization helper used to indicate when an application is ready to serve requests.
func NewReadySignal ¶
func NewReadySignal() *ReadySignalImpl
NewReadySignal creates and returns a new ReadySignalImpl instance.
func (*ReadySignalImpl) Add ¶ added in v1.3.0
func (s *ReadySignalImpl) Add()
Add increments the WaitGroup counter.
func (*ReadySignalImpl) Close ¶ added in v1.3.0
func (s *ReadySignalImpl) Close()
Close closes the signal channel, notifying all goroutines waiting on it.
func (*ReadySignalImpl) Intercept ¶ added in v1.3.0
func (s *ReadySignalImpl) Intercept()
Intercept marks the signal as intercepted.
func (*ReadySignalImpl) Intercepted ¶ added in v1.3.0
func (s *ReadySignalImpl) Intercepted() bool
Intercepted returns true if the signal has been intercepted.
func (*ReadySignalImpl) TriggerAndWait ¶ added in v1.3.0
func (s *ReadySignalImpl) TriggerAndWait() <-chan struct{}
TriggerAndWait marks an operation as done by decrementing the WaitGroup counter, and then returns the readiness signal channel for waiting.
func (*ReadySignalImpl) Wait ¶ added in v1.3.0
func (s *ReadySignalImpl) Wait()
Wait blocks until all WaitGroup counters reach zero.
type Runner ¶ added in v1.3.0
Runner defines an interface for components that need to be executed after all beans have been injected but before servers start.
type Server ¶ added in v1.3.0
type Server interface {
Run(ctx context.Context, sig ReadySignal) error
Stop() error
}
Server defines the lifecycle of application servers (e.g., HTTP, gRPC). It provides methods to start and gracefully stop the server.
type ServerMockImpl ¶ added in v1.3.0
type ServerMockImpl struct {
// contains filtered or unexported fields
}
ServerMockImpl is a generated mock implementation of the Server interface.
func NewServerMockImpl ¶ added in v1.3.0
func NewServerMockImpl(r *gsmock.Manager) *ServerMockImpl
NewServerMockImpl creates a new mock instance for Server with the given gsmock.Manager. Returns an initialized struct ready for registering mock behavior.
func (*ServerMockImpl) MockRun ¶ added in v1.3.0
func (impl *ServerMockImpl) MockRun() *gsmock.Mocker21[context.Context, ReadySignal, error]
MockRun returns a Mocker21 for registering mock behavior of Run with specific parameter and return types.
func (*ServerMockImpl) MockStop ¶ added in v1.3.0
func (impl *ServerMockImpl) MockStop() *gsmock.Mocker01[error]
MockStop returns a Mocker01 for registering mock behavior of Stop with specific parameter and return types.
func (*ServerMockImpl) Run ¶ added in v1.3.0
func (impl *ServerMockImpl) Run(ctx context.Context, sig ReadySignal) error
Run calls the registered mock for Run via gsmock.Invoke. If no matching mock is registered, it panics.
func (*ServerMockImpl) Stop ¶ added in v1.3.0
func (impl *ServerMockImpl) Stop() error
Stop calls the registered mock for Stop via gsmock.Invoke. If no matching mock is registered, it panics.