aedilis

package module
v0.1.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

'Aedilis' is a latin word for a Roman official who was responsible for governing public buildings and festival activities.

As a software library, aedilis provides a structure for orchestrating and running an application.

Init and Action Functions

Documentation

Index

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.

func (*ComponentRegistry) Get

func (mgr *ComponentRegistry) Get(name string) (Component, bool)

Get returns the named component if it exists, otherwise nil

type Console added in v0.1.6

type Console struct {
	// contains filtered or unexported fields
}

func NewConsole added in v0.1.6

func NewConsole(name string) *Console

func (*Console) Clear added in v0.1.8

func (c *Console) Clear() string

func (*Console) String added in v0.1.6

func (c *Console) String() string

func (*Console) Write added in v0.1.6

func (c *Console) Write(msg string, opt ...any)

func (*Console) WriteError added in v0.1.6

func (c *Console) WriteError(msg string, opt ...any)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL