factory

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewProviderFromIdxMap

func NewProviderFromIdxMap[P Provider, C Configurable](
	ctx context.Context,
	config C,
	factories IdxMap[ProviderFactory[P, C]],
	key string,
) (p P, err error)

NewProviderFromNamedMap creates a provider instance from a factory map using the given key

Types

type Configurable

type Configurable interface {
	// Check if config is valid.
	Validate() error
}

Configurable defines an interface that configs must implement.

type CreatorFunc

type CreatorFunc func() Configurable

CreatorFunc is a function that returns a new Configurable.

type Factory

type Factory interface {
	Idx
	NewConfig() Configurable
}

Config defines something that expose its uique name.

func NewFactory

func NewFactory(id Id, cf CreatorFunc) Factory

NewFactory returns a new Factory instance.

type Id

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

func MustNewId

func MustNewId(id string) Id

func NewId

func NewId(id string) (Id, error)

func (Id) String

func (id Id) String() string

type Idx

type Idx interface {
	Id() Id
}

type IdxMap

type IdxMap[T Idx] struct {
	// contains filtered or unexported fields
}

func MustNewIdxMap

func MustNewIdxMap[T Idx](factories ...T) IdxMap[T]

func NewIdxMap

func NewIdxMap[T Idx](factories ...T) (IdxMap[T], error)

func (*IdxMap[T]) Add

func (i *IdxMap[T]) Add(factory T) (err error)

func (*IdxMap[T]) Get

func (i *IdxMap[T]) Get(idstr string) (t T, err error)

func (*IdxMap[T]) GetInOrder

func (i *IdxMap[T]) GetInOrder() []T

type IdxService

type IdxService interface {
	Idx
	Service
}

func NewIdxService

func NewIdxService(id Id, service Service) IdxService

type NewProviderFunc

type NewProviderFunc[P Provider, C Configurable] func(ctx context.Context, config C) (P, error)

NewProviderFunc defines a function that creates a new provider

type Provider

type Provider = any

Provider is a constraint for any type

type ProviderFactory

type ProviderFactory[P Provider, C Configurable] interface {
	Idx
	New(context.Context, C) (P, error)
}

ProviderFactory defines an interface for a typed provider factory

func NewProviderFactory

func NewProviderFactory[P Provider, C Configurable](id Id, fn NewProviderFunc[P, C]) ProviderFactory[P, C]

NewProviderFactory returns a new generic provider factory

type Registry

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

func NewRegistry

func NewRegistry(services ...IdxService) (*Registry, error)

func (*Registry) Start

func (r *Registry) Start(ctx context.Context)

func (*Registry) Stop

func (r *Registry) Stop(ctx context.Context) error

func (*Registry) Wait

func (r *Registry) Wait(ctx context.Context) error

type Service

type Service interface {
	Start(context.Context) error
	Stop(context.Context) error
}

Jump to

Keyboard shortcuts

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