launcher

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 13 Imported by: 6

Documentation

Index

Constants

View Source
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)
}

func New

func New(opts ...Option) ILauncher

New creates a new launcher.

type IServicesRunner

type IServicesRunner interface {
	// Register services
	Register(services ...*Service)
	// Services return all registered services
	Services() []*Service
}

type Option

type Option func(*Options)

func WithAfterStart

func WithAfterStart(fn func() error) Option

WithAfterStart run funcs after service starts.

func WithAfterStop

func WithAfterStop(fn func() error) Option

WithAfterStop run funcs after service stops.

func WithAppStartStopLog added in v0.2.2

func WithAppStartStopLog(v bool) Option

func WithBeforeStart

func WithBeforeStart(fn func() error) Option

WithBeforeStart run funcs before service starts.

func WithBeforeStop

func WithBeforeStop(fn func() error) Option

WithBeforeStop run funcs before service stops.

func WithContext

func WithContext(ctx context.Context) Option

func WithLogger

func WithLogger(l logger.ExtendedLogger) Option

func WithName

func WithName(n string) Option

Name of the launcher.

func WithOpsConfig added in v0.1.0

func WithOpsConfig(c ops.Config) Option

func WithRunnerServicesSequence added in v0.1.0

func WithRunnerServicesSequence(v RunnerServicesSequence) Option

func WithSignal

func WithSignal(b bool) Option

func WithVersion

func WithVersion(v string) Option

Version of the launcher.

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) Name added in v0.3.0

func (s Service) Name() string

func (*Service) Options added in v0.3.0

func (s *Service) Options() *ServiceOptions

func (*Service) Start added in v0.3.0

func (s *Service) Start() error

func (*Service) Stop added in v0.3.0

func (s *Service) Stop() error

func (Service) String added in v0.3.0

func (s Service) String() string

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.

func WithStart added in v0.3.0

func WithStart(fn func(context.Context) error) ServiceOption

WithStart sets the start function of the service.

func WithStop added in v0.3.0

func WithStop(fn func(context.Context) error) ServiceOption

WithStop sets the stop function 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

Directories

Path Synopsis
services

Jump to

Keyboard shortcuts

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