service

package
v0.2.34 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2025 License: MIT Imports: 7 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Enabler

type Enabler interface {
	Enabled() bool
}

type HealthChecker added in v0.1.0

type HealthChecker interface {
	Name() string
	Interval() time.Duration
	Healthy(ctx context.Context) error
}

HealthChecker provides functionality to check health of any entity that implement this interface.

type IService

type IService interface {
	Name() string
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
}

type Option

type Option func(o *Options)

func WithAfterStart

func WithAfterStart(fn func() error) Option

WithAfterStart run funcs after service starts.

func WithAfterStartFinished

func WithAfterStartFinished(fn func() error) Option

WithAfterStartFinished run funcs after was finished service start func.

func WithAfterStop

func WithAfterStop(fn func() error) Option

WithAfterStop run funcs after service stops.

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 WithEnabled

func WithEnabled(v bool) Option

func WithLogger

func WithLogger(l logger.Logger) Option

func WithName

func WithName(n string) Option

Name of the service.

func WithService

func WithService(svc any) Option

func WithShutdownTimeout

func WithShutdownTimeout(v time.Duration) Option

func WithSignal

func WithSignal(b bool) Option

HandleSignal toggles automatic installation of the signal handler that traps TERM, INT, and QUIT. Users of this feature to disable the signal handler, should control liveness of the service through the context.

func WithStart

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

func WithStop

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

type Options

type Options struct {
	Logger logger.Logger

	Name          string
	Enabled       bool
	HealthChecker 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

	Signal bool

	Context context.Context //nolint:containedctx

	// Default 10 seconds
	ShutdownTimeout time.Duration
}

Options for service.

func (*Options) Validate

func (s *Options) Validate() error

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Service

func (Service) Name

func (s Service) Name() string

func (*Service) Options

func (s *Service) Options() *Options

func (*Service) Start

func (s *Service) Start() error

func (*Service) Stop

func (s *Service) Stop() error

func (Service) String

func (s Service) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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