Documentation ¶
Overview ¶
Package application define a simple application life cycle which should be robust enough for most of the application or be extended by your own custom implementation if it does not.
The application will start by initializing every given components, linking them to each other with the Inventory.
The components which implements the optional Validator interface will then be validated, any returned error will abort the application.
If no error has been returned, the application will then move to the next phase. Every components which implements the option StartHook interface will be started in the same order than it was given in the call to WithComponents. Returning an error from the Start callback will abort the application.
Finally, the application will run until it receives an interruption signal, or its context has been canceled or expired, or an error has been returned from the Start callback,
Once the application initiate its interruption, the components implementing the StopHook interface will be asked to stop and forcefully stopped if they do not perform after the configured grace period. The components will be stopped in the reverse order than the one given in the call to WithComponents.
Index ¶
- func WithComponent(component scaffolder.Component, opts ...scaffolder.Option) scaffolder.Option
- func WithGracefulPeriod(duration time.Duration) scaffolder.Option
- func WithName(name string) scaffolder.Option
- func WithVersion(version string) scaffolder.Option
- type Application
- type StartHook
- type StopHook
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithComponent ¶
func WithComponent(component scaffolder.Component, opts ...scaffolder.Option) scaffolder.Option
WithComponent is used to attach register a component in the application life cycle.
func WithGracefulPeriod ¶
func WithGracefulPeriod(duration time.Duration) scaffolder.Option
WithGracefulPeriod set the grace period allocated for stopping a component. The default value is one second.
func WithName ¶
func WithName(name string) scaffolder.Option
WithName set the application name, the default value is the binary name.
func WithVersion ¶
func WithVersion(version string) scaffolder.Option
WithVersion set the version of the application, the default value is "0.0.0".
Types ¶
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
Application should describe your application.
func New ¶
func New(opts ...scaffolder.Option) (*Application, error)
New build an application and customize it with the given Options.
func (*Application) Default ¶
func (a *Application) Default()
Default assign the default variables for the application component.
func (*Application) Run ¶
func (a *Application) Run(ctx context.Context) (err error)
Run the application until it receives an interruption signal, or until its context has been canceled or expired, or until an error has been returned from the Start callback.
The application would return an error if it was unable to Add a component, links the components, validate the components, start the components or stop the components.
func (*Application) String ¶
func (a *Application) String() string
String implements the Stringer interface.
type StartHook ¶
StartHook define the interface for long running process which must run in parallel with the application.