component

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2025 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const Global = "Global"

Global is the instance name for the global component.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, groups ...Group) error

func RunUntilReady

func RunUntilReady(waitCtx context.Context, component Component, timeout time.Duration) error

Types

type Base

type Base[Config any, Dependencies any] struct {
	// contains filtered or unexported fields
}

Base is the base implementation of a component. It provides partial, default implementations of the Component interface. It SHOULD BE used as an embedded field in the actual component implementation.

func New

func New[Config any, Dependencies any](config *BaseConfig[Config, Dependencies]) *Base[Config, Dependencies]

func (*Base[Config, Dependencies]) Close

func (c *Base[Config, Dependencies]) Close() error

func (*Base[Config, Dependencies]) Config

func (c *Base[Config, Dependencies]) Config() *Config

func (*Base[Config, Dependencies]) Context

func (c *Base[Config, Dependencies]) Context() context.Context

func (*Base[Config, Dependencies]) Dependencies

func (c *Base[Config, Dependencies]) Dependencies() Dependencies

func (*Base[Config, Dependencies]) Instance

func (c *Base[Config, Dependencies]) Instance() string

func (*Base[Config, Dependencies]) MarkReady

func (c *Base[Config, Dependencies]) MarkReady()

func (*Base[Config, Dependencies]) Name

func (c *Base[Config, Dependencies]) Name() string

func (*Base[Config, Dependencies]) Ready

func (c *Base[Config, Dependencies]) Ready() <-chan struct{}

func (*Base[Config, Dependencies]) Run

func (c *Base[Config, Dependencies]) Run() error

func (*Base[Config, Dependencies]) SetConfig

func (c *Base[Config, Dependencies]) SetConfig(config *Config)

func (*Base[Config, Dependencies]) TelemetryLabels

func (c *Base[Config, Dependencies]) TelemetryLabels() telemetry.Labels

func (*Base[Config, Dependencies]) TelemetryLabelsID

func (c *Base[Config, Dependencies]) TelemetryLabelsID() prometheus.Labels

func (*Base[Config, Dependencies]) TelemetryLabelsIDFields

func (c *Base[Config, Dependencies]) TelemetryLabelsIDFields() []string

type BaseConfig

type BaseConfig[Config any, Dependencies any] struct {
	Name                      string
	Instance                  string
	AdditionalTelemetryLabels telemetry.Labels
	Config                    *Config
	Dependencies              Dependencies
}

type Component

type Component interface {
	// Name returns the name of the component. e.g. "KVStorage".
	// It SHOULD be unique between different components.
	// It will used as the telemetry info. e.g. log, metrics, etc.
	Name() string
	// Instance returns the instance name of the component. e.g. "kvstorage-1".
	// It SHOULD be unique between different instances of the same component.
	// It will used as the telemetry info. e.g. log, metrics, etc.
	Instance() string
	// Run starts the component.
	// It blocks until the component is closed.
	// It MUST be called only once.
	Run() (err error)
	// Ready returns a channel that is closed when the component is ready.
	// Returns a chan to notify the component is ready when Run is called.
	Ready() (notify <-chan struct{})
	// Close closes the component.
	Close() (err error)
}

Component is the interface for a component. It is used to start, stop and monitor a component. A component means it is runnable, has some async work to do. ALL exported biz structs MUST implement this interface.

type Factory

type Factory[ComponentImpl Component, Config any, Dependencies any] interface {
	New(instance string, config *Config, dependencies Dependencies) (ComponentImpl, error)
}

type FactoryFunc

type FactoryFunc[ComponentImpl Component, Config any, Dependencies any] func(
	instance string,
	config *Config,
	dependencies Dependencies,
) (ComponentImpl, error)

func (FactoryFunc[ComponentImpl, Config, Dependencies]) New

func (f FactoryFunc[ComponentImpl, Config, Dependencies]) New(
	instance string,
	config *Config,
	dependencies Dependencies,
) (ComponentImpl, error)

type Group

type Group []Component

type Mock

type Mock struct {
	mock.Mock
}

func (*Mock) Close

func (m *Mock) Close() error

func (*Mock) Instance

func (m *Mock) Instance() string

func (*Mock) Name

func (m *Mock) Name() string

func (*Mock) Ready

func (m *Mock) Ready() <-chan struct{}

func (*Mock) Run

func (m *Mock) Run() error

type MockOption

type MockOption func(m *mock.Mock)

type MockOptions

type MockOptions []MockOption

func (MockOptions) Apply

func (m MockOptions) Apply(mock *Mock)

Jump to

Keyboard shortcuts

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