Documentation
¶
Index ¶
- Constants
- type ILauncher
- type IServicesRunner
- type Option
- func WithAfterStart(fn func() error) Option
- func WithAfterStop(fn func() error) Option
- func WithAppStartStopLog(v bool) Option
- func WithBeforeStart(fn func() error) Option
- func WithBeforeStop(fn func() error) Option
- func WithContext(ctx context.Context) Option
- func WithLogger(l logger.ExtendedLogger) Option
- func WithName(n string) Option
- func WithOpsConfig(c ops.Config) Option
- func WithRunnerServicesSequence(v RunnerServicesSequence) Option
- func WithSignal(b bool) Option
- func WithVersion(v string) Option
- type Options
- type RunnerServicesSequence
- type Service
- type ServiceOption
- func WithEnabled(v bool) ServiceOption
- func WithService(svc any) ServiceOption
- func WithServiceAfterStart(fn func() error) ServiceOption
- func WithServiceAfterStartFinished(fn func() error) ServiceOption
- func WithServiceAfterStop(fn func() error) ServiceOption
- func WithServiceBeforeStart(fn func() error) ServiceOption
- func WithServiceBeforeStop(fn func() error) ServiceOption
- func WithServiceContext(ctx context.Context) ServiceOption
- func WithServiceLogger(l logger.Logger) ServiceOption
- func WithServiceName(n string) ServiceOption
- func WithShutdownTimeout(v time.Duration) ServiceOption
- func WithStart(fn func(context.Context) error) ServiceOption
- func WithStop(fn func(context.Context) error) ServiceOption
- type ServiceOptions
Constants ¶
const ( RunnerServicesSequenceNone = iota RunnerServicesSequenceFifo RunnerServicesSequenceLifo )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ILauncher ¶
type ILauncher interface {
// Run launcher and all services
Run() error
// Stop launcher and all services
Stop()
// ServicesRunner return services runner
ServicesRunner() IServicesRunner
// Context return global context
Context() context.Context
// AddBeforeStartHooks adds before start hooks
AddBeforeStartHooks(hook ...func() error)
// AddBeforeStopHooks adds before stop hooks
AddBeforeStopHooks(hook ...func() error)
// AddAfterStartHooks adds after start hooks
AddAfterStartHooks(hook ...func() error)
// AddAfterStopHooks adds after stop hooks
AddAfterStopHooks(hook ...func() error)
}
type IServicesRunner ¶
type Option ¶
type Option func(*Options)
func WithAfterStart ¶
WithAfterStart run funcs after service starts.
func WithAfterStop ¶
WithAfterStop run funcs after service stops.
func WithAppStartStopLog ¶ added in v0.2.2
func WithBeforeStart ¶
WithBeforeStart run funcs before service starts.
func WithBeforeStop ¶
WithBeforeStop run funcs before service stops.
func WithContext ¶
func WithLogger ¶
func WithLogger(l logger.ExtendedLogger) Option
func WithOpsConfig ¶ added in v0.1.0
func WithRunnerServicesSequence ¶ added in v0.1.0
func WithRunnerServicesSequence(v RunnerServicesSequence) Option
func WithSignal ¶
type Options ¶
type Options struct {
Name string
Version string
// Before and After funcs
BeforeStart []func() error
BeforeStop []func() error
AfterStart []func() error
AfterStop []func() error
AppStartStopLog bool
RunnerServicesSequence RunnerServicesSequence
Signal bool
Context context.Context //nolint:containedctx
OpsConfig ops.Config
// contains filtered or unexported fields
}
type RunnerServicesSequence ¶ added in v0.1.0
type RunnerServicesSequence int
type Service ¶ added in v0.3.0
type Service struct {
// contains filtered or unexported fields
}
Service wraps a lifecycle-managed unit with Start/Stop functions and hooks.
func NewService ¶ added in v0.3.0
func NewService(opts ...ServiceOption) *Service
NewService creates a new Service.
func (*Service) Options ¶ added in v0.3.0
func (s *Service) Options() *ServiceOptions
type ServiceOption ¶ added in v0.3.0
type ServiceOption func(o *ServiceOptions)
ServiceOption is a function that configures a ServiceOptions.
func WithEnabled ¶ added in v0.3.0
func WithEnabled(v bool) ServiceOption
WithEnabled sets the enabled state of the service.
func WithService ¶ added in v0.3.0
func WithService(svc any) ServiceOption
WithService wraps any value that implements Name/Start/Stop/Enabled/HealthChecker.
func WithServiceAfterStart ¶ added in v0.3.0
func WithServiceAfterStart(fn func() error) ServiceOption
WithServiceAfterStart runs fn after service starts.
func WithServiceAfterStartFinished ¶ added in v0.3.0
func WithServiceAfterStartFinished(fn func() error) ServiceOption
WithServiceAfterStartFinished runs fn after the service Start func finishes.
func WithServiceAfterStop ¶ added in v0.3.0
func WithServiceAfterStop(fn func() error) ServiceOption
WithServiceAfterStop runs fn after service stops.
func WithServiceBeforeStart ¶ added in v0.3.0
func WithServiceBeforeStart(fn func() error) ServiceOption
WithServiceBeforeStart runs fn before service starts.
func WithServiceBeforeStop ¶ added in v0.3.0
func WithServiceBeforeStop(fn func() error) ServiceOption
WithServiceBeforeStop runs fn before service stops.
func WithServiceContext ¶ added in v0.3.0
func WithServiceContext(ctx context.Context) ServiceOption
func WithServiceLogger ¶ added in v0.3.0
func WithServiceLogger(l logger.Logger) ServiceOption
func WithServiceName ¶ added in v0.3.0
func WithServiceName(n string) ServiceOption
WithServiceName sets the name of the service.
func WithShutdownTimeout ¶ added in v0.3.0
func WithShutdownTimeout(v time.Duration) ServiceOption
WithShutdownTimeout sets the shutdown timeout of the service.
type ServiceOptions ¶ added in v0.3.0
type ServiceOptions struct {
Logger logger.Logger
Name string
Enabled bool
HealthChecker types.HealthChecker
StartFn func(ctx context.Context) error
StopFn func(ctx context.Context) error
// Before and After funcs
BeforeStart []func() error
BeforeStop []func() error
AfterStart []func() error
AfterStartFinished []func() error
AfterStop []func() error
Context context.Context //nolint:containedctx
// Default 10 seconds
ShutdownTimeout time.Duration
}
ServiceOptions holds configuration for a Service.
func (*ServiceOptions) Validate ¶ added in v0.3.0
func (s *ServiceOptions) Validate() error