Documentation ¶
Overview ¶
This package provides dependency injection and lifecycle management for component based monolith architecture. Dependency injection feature is based on reflection. The package also provides Initer, Starter and Stopper interfaces for lifecycle management. A component is a struct which implements one or several interfaces.
Index ¶
- type DefaultLogger
- type GracefulStopper
- type Initer
- type Logger
- type Manager
- func (m *Manager) GracefulStop(ctx context.Context) error
- func (m *Manager) Init(ctx context.Context) error
- func (m *Manager) Inject(components ...interface{})
- func (m *Manager) Register(components ...interface{})
- func (m *Manager) SetLogger(logger Logger)
- func (m *Manager) Start(ctx context.Context) error
- func (m *Manager) Stop(ctx context.Context) error
- type NoLogger
- type Starter
- type Stopper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultLogger ¶
type DefaultLogger struct{}
DefaultLogger logs to std out
func (*DefaultLogger) Debug ¶
func (l *DefaultLogger) Debug(v ...interface{})
func (*DefaultLogger) Debugf ¶
func (l *DefaultLogger) Debugf(format string, v ...interface{})
type GracefulStopper ¶
GracefulStopper interface provides method to end work with other components.
type Initer ¶
Initer interface provides method to init a component. During initialization components may NOT be ready. Only safe methods (e.g. not dependant on other components) can be called during initialization.
type Logger ¶
type Logger interface { Debug(v ...interface{}) Debugf(format string, v ...interface{}) }
Logger interface provides methods for debug logging
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager provide methods to manage components lifecycle
func NewManager ¶
NewManager creates new component manager with default logger
func (*Manager) GracefulStop ¶
Stop invokes Stop method of all components which implements Starter interface
func (*Manager) Inject ¶
func (m *Manager) Inject(components ...interface{})
Inject components in Manager and inject required dependencies Inject can inject interfaces only, tag public struct fields with `inject:""`
func (*Manager) Register ¶
func (m *Manager) Register(components ...interface{})
Register components in Manager and inject required dependencies. Register can inject interfaces only, tag public struct fields with `inject:""`. If the injectable struct already has a value on the tagged field, the value WILL NOT be overridden.