Documentation
¶
Index ¶
- Constants
- Variables
- func Go() error
- func Override(create func() Component)
- func OverrideName(name string, create func() Component)
- func QualifiedName(v any) string
- func Register(create func() Component)
- func RegisterName(name string, create func() Component)
- func Shutdown()
- func Split(s, sep, quote string) []string
- func Test(mocks ...Component) error
- type Component
- type DependencyInjectionError
- type EventBus
- type Flag
- type Phase
- type Process
- type Runtime
- type State
Constants ¶
const (
// DefaultName is used when registering components without an explicit name.
DefaultName = "default"
)
Variables ¶
Functions ¶
func OverrideName ¶
OverrideName overrides a factory function with the given name.
func QualifiedName ¶
QualifiedName returns the full name of a struct, function or a simple name of a primitive.
func RegisterName ¶
RegisterName registers a factory function with the given name.
func Shutdown ¶
func Shutdown()
Shutdown boot-go instance. All components will be stopped. This is equivalent with issuing a SIGTERM on process level.
Types ¶
type Component ¶
type Component interface {
// Init initializes data, set the default configuration, subscribe to events
// or performs other kind of configuration.
Init() error
}
Component represent functional building blocks, which solve one specific purpose. They should be fail tolerant, recoverable, agnostic and decent.
fail tolerant: Don't stop processing on errors. Example: A http request can still be processed, even when the logging server is not available anymore.
recoverable: Try to recover from errors. E.g. a database component should try to reconnect after lost connection.
agnostic: Behave the same in any environment. E.g. a key-value store component should work on a local development machine the same way as in a containerized environment.
decent: Don't overload the developer with complexity. E.g. keep the interface and events as simple as possible. Less is often more.
type DependencyInjectionError ¶
type DependencyInjectionError struct {
// contains filtered or unexported fields
}
DependencyInjectionError contains a detail description for the cause of the injection failure
func (*DependencyInjectionError) Error ¶
func (e *DependencyInjectionError) Error() string
type EventBus ¶
type EventBus interface {
// Subscribe subscribes to a message type.
// Returns error if handler fails.
Subscribe(handler any) error
// Unsubscribe removes handler defined for a message type.
// Returns error if there are no handlers subscribed to the message type.
Unsubscribe(handler any) error
// Publish executes handler defined for a message type.
Publish(event any) (err error)
// HasMessageHandler returns true if exists any handler subscribed to the message type.
HasMessageHandler(event any) bool
}
EventBus provides the ability to decouple components. It is designed as a replacement for direct methode calls, so components can subscribe for messages produced by other components.
func NewTestableEventBus ¶
func NewTestableEventBus() EventBus
NewTestableEventBus can be used for unit testing.
type Flag ¶
type Flag string
Flag describes a special behaviour of a component
const ( // StandardFlag is set when the component is started in unit test mode. StandardFlag Flag = "standard" // UnitTestFlag is set when the component is started in unit test mode. UnitTestFlag Flag = "unitTest" // FunctionalTestFlag is set when the component is started in functional test mode. FunctionalTestFlag Flag = "functionalTest" )
type Phase ¶
type Phase uint8
Phase describes the status of the boot-go instance
const ( // Initializing is set directly after the application started. // In this phase it is safe to subscribe to events. Initializing Phase = iota // Booting is set when starting the boot framework. Booting // Running is set when all components were initialized and started Running // Stopping is set when all components are requested to stop their service. Stopping // Exiting is set when all components were stopped. Exiting )
type Process ¶
type Process interface {
Component
// Start is called as soon as all boot.Component components are initialized. The call should be
// blocking until all processing is completed.
Start() error
// Stop is called to abort the processing and clean up resources. Pay attention that the
// processing may already be stopped.
Stop() error
}
Process is a Component which has a processing functionality. This can be anything like a server, cron job or long-running process.
type Runtime ¶
Runtime is a standard component, which is used to alternate the component behaviour at runtime.
type State ¶
type State int
State is used to describe the current state of a component instance
const ( // Created is set directly after the component was created by the provided factory Created State = iota // Initialized is set after the component Init() function was called Initialized // Started is set after the component Start() function was called Started // Stopped is set after the component Stop() function was called Stopped )