Documentation ¶
Index ¶
- func GetComponent[T Component](app *Application, name string) (T, error)
- func Init(app *Application, initializers ...InitFunc) error
- func MustGetComponent[T Component](app *Application, name string) T
- type ActionRegistry
- type Application
- func (app *Application) Init(initializer InitFunc) error
- func (app *Application) RegisterCloser(name string, closer ComponentFunc)
- func (app *Application) RegisterComponent(name string, component Component) error
- func (app *Application) RegisterStarter(name string, starter ComponentFunc) error
- func (app *Application) Run(initializers ...InitFunc) error
- func (app *Application) Start() error
- func (app *Application) StartWithInterruptWrapper(startFunc ComponentFunc) ComponentFunc
- func (app *Application) Stop()
- type CloseFunc
- type Component
- type ComponentFunc
- type ComponentOptions
- type ComponentRegistry
- type Console
- type InitFunc
- type StartFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetComponent ¶
func GetComponent[T Component](app *Application, name string) (T, error)
GetComponent fetches the named component object from the registry as the given generic type.
func Init ¶
func Init(app *Application, initializers ...InitFunc) error
func MustGetComponent ¶
func MustGetComponent[T Component](app *Application, name string) T
MustGetComponent fetches the named component object from the registry. If the component does not exist panic is raised.
Types ¶
type ActionRegistry ¶
type ActionRegistry struct {
// contains filtered or unexported fields
}
ActionRegistry manages a list of functions that perform specific application functions. Example component starter or closing functions.
func NewActionRegistry ¶
func NewActionRegistry(name string) *ActionRegistry
func (*ActionRegistry) Add ¶
func (reg *ActionRegistry) Add(name string, f ComponentFunc)
Add a new component function to the registry.
func (*ActionRegistry) Count ¶
func (reg *ActionRegistry) Count() int
Count return the number of registered component functions.
func (*ActionRegistry) Execute ¶
func (reg *ActionRegistry) Execute(app *Application, haltOnErr bool) error
Execute all the functions in the registry in the order registered.
func (*ActionRegistry) ExecuteReverse ¶
func (reg *ActionRegistry) ExecuteReverse(app *Application, haltOnErr bool) error
ExecuteReverse the functions in the registry in the reverse order they were registered.
type Application ¶
type Application struct { Console *Console // contains filtered or unexported fields }
func New ¶
func New(name string) *Application
func (*Application) Init ¶
func (app *Application) Init(initializer InitFunc) error
Init takes a component initialization function and calls it immediately.
func (*Application) RegisterCloser ¶ added in v0.1.5
func (app *Application) RegisterCloser(name string, closer ComponentFunc)
func (*Application) RegisterComponent ¶ added in v0.1.2
func (app *Application) RegisterComponent(name string, component Component) error
RegisterComponent adds the named component to the registry.
func (*Application) RegisterStarter ¶ added in v0.1.5
func (app *Application) RegisterStarter(name string, starter ComponentFunc) error
func (*Application) Run ¶
func (app *Application) Run(initializers ...InitFunc) error
func (*Application) Start ¶
func (app *Application) Start() error
Start run all starter functions in order they were registered.
func (*Application) StartWithInterruptWrapper ¶ added in v0.1.9
func (app *Application) StartWithInterruptWrapper(startFunc ComponentFunc) ComponentFunc
func (*Application) Stop ¶
func (app *Application) Stop()
Stop runs all closer functions in reverse order registered.
type CloseFunc ¶
type CloseFunc func(app *Application) error
type Component ¶
type Component interface{}
Component can be any type, but the general idea is it represents a piece of application functionality such as logger, configuration manager, global error handler, service managers, etc.
type ComponentFunc ¶
type ComponentFunc func(app *Application) error
ComponentFunc is a function type returned during component initialization that represents an action that can be called by the application. An action could start or shutdown the component.
type ComponentOptions ¶ added in v0.1.3
type ComponentOptions struct { Component Component Starter ComponentFunc Closer ComponentFunc Alias string }
func ComponentError ¶ added in v0.1.3
func ComponentError(err error) (ComponentOptions, error)
func (*ComponentOptions) Name ¶ added in v0.1.3
func (co *ComponentOptions) Name() string
type ComponentRegistry ¶
type ComponentRegistry struct {
// contains filtered or unexported fields
}
ComponentRegistry maintains a named list of application components.
func NewComponentRegistry ¶
func NewComponentRegistry() *ComponentRegistry
NewComponentRegistry creates a new registry object.
func (*ComponentRegistry) Add ¶
func (mgr *ComponentRegistry) Add(name string, component Component) error
Add adds the named component.
func (*ComponentRegistry) Count ¶
func (mgr *ComponentRegistry) Count() int
Count returns the number of components registered.
type Console ¶ added in v0.1.6
type Console struct {
// contains filtered or unexported fields
}
func NewConsole ¶ added in v0.1.6
func (*Console) WriteError ¶ added in v0.1.6
type InitFunc ¶
type InitFunc func(app *Application) (ComponentOptions, error)
InitFunc is a function type specific to initializing a component. It must return the initialized component object and a start and shutdown function. These could all be nil. There is no specific requirement that they exist.
type StartFunc ¶
type StartFunc func(app *Application) error