modules

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 7 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotReady = errors.New("module not ready")

ErrNotReady is returned by Ready for a module that has not finished starting.

Functions

This section is empty.

Types

type Base

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

func (*Base) AddDependencies

func (b *Base) AddDependencies(deps ...string)

func (*Base) Dependencies

func (b *Base) Dependencies() map[string]Module

func (*Base) Dependency

func (b *Base) Dependency(name string) Module

func (*Base) IsReady added in v0.2.0

func (b *Base) IsReady() bool

func (*Base) Log

func (b *Base) Log(lvl zerolog.Level, message string, fields ...any)

func (*Base) Logger

func (b *Base) Logger() *zerolog.Logger

func (*Base) ManageReadiness added in v0.2.0

func (b *Base) ManageReadiness()

ManageReadiness opts the module out of the runtime marking it ready when Start returns. A module that does so is responsible for calling SetReady itself, and stays unready until it does.

func (*Base) ManagesReadiness added in v0.2.0

func (b *Base) ManagesReadiness() bool

func (*Base) Name

func (b *Base) Name() string

func (*Base) Ready added in v0.2.0

func (b *Base) Ready(_ context.Context) error

Ready reports readiness from the readiness flag. Modules that need a richer answer - a probe query, an error captured by a background goroutine - embed Base and override this.

func (*Base) SetDependency

func (b *Base) SetDependency(m Module)

func (*Base) SetLogger

func (b *Base) SetLogger(l *zerolog.Logger)

func (*Base) SetName

func (b *Base) SetName(name string)

func (*Base) SetReady added in v0.2.0

func (b *Base) SetReady(ready bool)

type Module

type Module interface {
	Configure(...Option) error
	Start() error
	Shutdown() error

	SetName(string)
	Name() string

	AddDependencies(...string)
	SetDependency(Module)
	Dependency(string) Module
	Dependencies() map[string]Module

	Ready(context.Context) error
	IsReady() bool
	SetReady(bool)

	// ManagesReadiness reports whether the module sets its own readiness. The
	// runtime marks every other module ready once its Start returns.
	ManageReadiness()
	ManagesReadiness() bool

	SetLogger(*zerolog.Logger)
	Logger() *zerolog.Logger
	Log(zerolog.Level, string, ...any)
}

type Option

type Option interface {
	Apply(Module) error
}

func WithLogger

func WithLogger(log *zerolog.Logger) Option

type ReadinessReporter added in v0.2.0

type ReadinessReporter interface {
	NotReady(context.Context) map[string]error
}

ReadinessReporter reports which modules are not yet ready to serve. The Runtime satisfies it, and modules that need to answer for the whole service - a health endpoint, a readiness probe - receive it through readinessAware rather than holding the Runtime itself.

type Runtime

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

func NewRuntime

func NewRuntime() *Runtime

func (*Runtime) Configure

func (r *Runtime) Configure() error

func (*Runtime) Module

func (r *Runtime) Module(name string) Module

func (*Runtime) NotReady added in v0.2.0

func (r *Runtime) NotReady(ctx context.Context) map[string]error

NotReady returns the modules that are not ready to serve, keyed by module name, with the reason each gave.

func (*Runtime) OrderModules

func (r *Runtime) OrderModules() error

func (*Runtime) Ready added in v0.2.0

func (r *Runtime) Ready(ctx context.Context) error

Ready reports whether every module is ready to serve. The returned error names each module that is not, in a stable order.

func (*Runtime) Register

func (r *Runtime) Register(m Module, opts ...Option)

func (*Runtime) Shutdown

func (r *Runtime) Shutdown() error

func (*Runtime) Start

func (r *Runtime) Start() error

Jump to

Keyboard shortcuts

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