Documentation
ΒΆ
Index ΒΆ
- Constants
- Variables
- type App
- type CloserOsSignal
- type Config
- type Option
- func WithCloser(closer closer.Closer, cmp *component.Component) Option
- func WithComponents(components ...*component.Component) Option
- func WithConfigurator(configurator configurator.Configurator, cmp *component.Component) Option
- func WithContainer(container container.Container, cmp *component.Component) Option
- func WithLogger(logger logger.Logger, cmp *component.Component) Option
- func WithOsSignalCloser() Option
Constants ΒΆ
const ( ClusterFieldName = "cluster" NamespaceFieldName = "namespace" ContainerIdFieldName = "container.id" ContainerNameFieldName = "container.name" HostnameFieldName = "hostname" InitDurationFieldName = "compogo.duration.init" ConfigurationDurationFieldName = "compogo.duration.configuration" PreExecuteDurationFieldName = "compogo.duration.execute.pre" ExecuteDurationFieldName = "compogo.duration.execute.run" PostExecuteDurationFieldName = "compogo.duration.execute.post" PreWaitDurationFieldName = "compogo.duration.wait.pre" PostWaitDurationFieldName = "compogo.duration.wait.post" PreStopDurationFieldName = "compogo.duration.stop.pre" StopDurationFieldName = "compogo.duration.stop.stop" PostStopDurationFieldName = "compogo.duration.stop.post" ClusterDefault = "unknown-cluster" NamespaceDefault = "unknown-namespace" ContainerIdDefault = "unknown-container_id" ContainerNameDefault = "unknown-container_name" HostnameDefault = "unknown-hostname" InitDurationDefault = 100 * time.Millisecond ConfigurationDurationDefault = 100 * time.Millisecond PreRunDurationDefault = 100 * time.Millisecond RunDurationDefault = 100 * time.Millisecond PostRunDurationDefault = 100 * time.Millisecond PreWaitDurationDefault = 100 * time.Millisecond PostWaitDurationDefault = 100 * time.Millisecond PreStopDurationDefault = 100 * time.Millisecond StopDurationDefault = 100 * time.Millisecond PostStopDurationDefault = 100 * time.Millisecond )
const ( MetricNamePrefix = "compogo_" MetricAppNameFieldName = "app" )
Variables ΒΆ
var ( ContainerUndefinedError = errors.New("container is undefined") ConfiguratorUndefinedError = errors.New("configurator is undefined") CloserUndefinedError = errors.New("closer is undefined") LoggerUndefinedError = errors.New("logger is undefined") AppIsRunningError = errors.New("app is running") ComponentStepTimeoutError = errors.New("timeout execution of the component at the step") )
Functions ΒΆ
This section is empty.
Types ΒΆ
type App ΒΆ
type App struct {
// contains filtered or unexported fields
}
App represents the main application container. It manages component lifecycle, dependencies, and graceful shutdown.
func NewApp ΒΆ
NewApp creates a new application instance with the given name and options. The config component is automatically added to ensure basic configuration is always present.
func (*App) AddComponents ΒΆ
AddComponents registers one or more components and their dependencies in the application. Components are initialized immediately and cannot be added while the app is running. Returns an error if validation fails or the app is already running.
func (*App) BindFlags ΒΆ
BindFlags binds command-line flags for all registered components. Must be called before Serve() and cannot be called while the app is running.
func (*App) Clone ΒΆ
Clone creates a child application that inherits all core services (config, container, configurator, closer) but has its own logger and component set. Useful for creating isolated sub-applications (e.g., for testing or modules).
func (*App) Serve ΒΆ
Serve starts the application and runs all components through their lifecycle: 1. Sequential execution of PreExecute, Execute, PostExecute, PreWait 2. Concurrent execution of all Wait components 3. Sequential execution of PostWait 4. Wait for shutdown signal or first error 5. Sequential execution of PreStop, Stop, PostStop 6. Wait for all goroutines to finish
type CloserOsSignal ΒΆ
type CloserOsSignal struct {
// contains filtered or unexported fields
}
func NewCloserOsSignal ΒΆ
func NewCloserOsSignal() *CloserOsSignal
func (*CloserOsSignal) Close ΒΆ
func (closer *CloserOsSignal) Close() error
func (*CloserOsSignal) GetContext ΒΆ
func (closer *CloserOsSignal) GetContext() context.Context
func (*CloserOsSignal) IsClosed ΒΆ
func (closer *CloserOsSignal) IsClosed() bool
func (*CloserOsSignal) Serve ΒΆ
func (closer *CloserOsSignal) Serve()
type Config ΒΆ
type Config struct {
Name string
PID uint64
// k8s
Cluster string
Namespace string
ContainerId string
ContainerName string
Hostname string
// Duration
InitDuration time.Duration
ConfigurationDuration time.Duration
ExecuteRunDuration time.Duration
ExecuteDuration time.Duration
PostExecuteDuration time.Duration
PreWaitDuration time.Duration
PostWaitDuration time.Duration
PreStopDuration time.Duration
StopDuration time.Duration
PostStopDuration time.Duration
}
func Configuration ΒΆ
func Configuration(config *Config, configurator configurator.Configurator) *Config
type Option ΒΆ
type Option func(app *App)
Option configures the App during creation. Options are applied in the order they are provided to NewApp.
func WithCloser ΒΆ
WithCloser injects a closer implementation and its component. The closer component will participate in the application lifecycle.
func WithComponents ΒΆ
WithComponents registers additional components during app creation. Panics if component registration fails (should only happen on programming errors).
func WithConfigurator ΒΆ
func WithConfigurator(configurator configurator.Configurator, cmp *component.Component) Option
WithConfigurator injects a configurator implementation and its component. The configurator component will participate in the application lifecycle.
func WithContainer ΒΆ
WithContainer injects a DI container implementation and its component. The container component will participate in the application lifecycle.
func WithLogger ΒΆ
WithLogger injects a logger implementation and its component into the app. The logger component will participate in the application lifecycle.
func WithOsSignalCloser ΒΆ
func WithOsSignalCloser() Option
WithOsSignalCloser returns an Option that adds a default closer listening for OS signals. The closer handles SIGINT, SIGTERM, and SIGABRT, providing graceful shutdown out of the box. Perfect for standard applications - just add this option and your app stops gracefully on Ctrl+C.