Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidObjectPath is returned when a key cannot be converted into // a nested object path like "foo...bar", ".foo", or "foo." ErrInvalidObjectPath = errors.New("invalid object path") )
Functions ¶
Types ¶
type Application ¶
type Application struct { sync.Mutex Name string Version string Controller *Controller Settings *config.Set Logger *slog.Logger // contains filtered or unexported fields }
Application defines an instance of an application
func FromContext ¶
func FromContext(ctx context.Context) *Application
FromContext extracts the Appliation instance if it exists from the provided context or nil if not found
func New ¶
func New(name, version string, opts ...Option) *Application
New creates a new application and executes the options
func (*Application) Exit ¶
func (a *Application) Exit(err error)
Exit will shutdown the application with the specified error.
This call can be made from any go routine, only the first call to Exit will be read (first in) and shutdown the application
func (*Application) Install ¶
func (a *Application) Install(ctx context.Context) error
Install will execute all modules that have an application.Initializer implementation, then all modules with that implement the application.Installer
func (*Application) Run ¶
func (a *Application) Run(ctx context.Context) error
Run the application returning the error that terminated execution or nil if terminated normally
func (*Application) String ¶
func (a *Application) String() string
String returns the application name/version
type Configurable ¶
type Configurable interface { // Config should return a pointer to an allocated configuration // structure. This structure will be written to directly with the // decoded configuration. If this returns nil, then it is as if // Configurable was not implemented. Config() (interface{}, error) }
Configurable can be optionally implemented by any module to accept user configuration.
type ConfigurableNotify ¶
type ConfigurableNotify interface { Configurable // ConfigSet is called with the value of the configuration after // decoding is complete successfully. ConfigSet(interface{}) error }
ConfigurableNotify is an optional interface that can be implemented by any module to receive a notification that the configuration was decoded.
type Configuration ¶
type Configuration struct{}
Configuration for the application based on github.com/hashicorp/hcl/v2
func (Configuration) Decode ¶
func (c Configuration) Decode(ctx context.Context, filename string, src []byte) hcl.Diagnostics
func (Configuration) DecodeFile ¶
func (c Configuration) DecodeFile(ctx context.Context, filename string) hcl.Diagnostics
DecodeFile will open and decode the provided file, returning an error when parsing fails
func (Configuration) EvalContext ¶
func (Configuration) EvalContext(ctx context.Context) *hcl.EvalContext
EvalContext returns the hcl.EvalContext for loading hcl files
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller for modules
func (*Controller) Add ¶
func (c *Controller) Add(name string, m Module)
Add the specified module, if a module with the same name exists, it will be overwritten
func (*Controller) Get ¶
func (c *Controller) Get(name string) Module
Get the module with the specified name, will return nil if no module is found
func (*Controller) Range ¶
func (c *Controller) Range(cb func(name string, module Module) bool)
Range over the modules
func (*Controller) Run ¶
func (c *Controller) Run(ctx context.Context) error
Run the added modules. This will run the lifetime on modules in the order they were added
Module lifetime is called in the following order: * if module is Initializer -> Initialize() * if module is PreStarter -> PreStart() * Start() * if module is PostStarter -> PostStart() * wait for context.Done() * Stop()
Stop() will be called on all module that Start() was successfully called on, even during error
type Error ¶
type Error struct {
Errors []error
}
Error for modules containing multiple errors
type Initializer ¶
Initializer allows for context modifications before start
type Installer ¶
Installer allows for modules to install things before and modul.PreStart is called, and is used in the application.Install function
type Option ¶
type Option func(app *Application)
Option for an Application
func WithConfigFile ¶
WithConfigFile adds hcl parsing capability to the application and loads the provided filename
func WithLogger ¶
WithLogger will set the internal slog.Logger instance
func WithModule ¶
WithModule adds the specified module to the application for execution
type PostStarter ¶
PostStarter allows for additional functionality after all Module.Start are called
type PreStarter ¶
PreStarter allows for additional functionality before any Module.Start is called