factory

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder added in v0.2.13

type Builder[T any, C any] interface {
	// WithConfig sets the configuration for the builder
	WithConfig(config C) Builder[T, C]
	// WithOptions sets the dependencies for the builder
	WithOptions(opts ...options.Option) Builder[T, C]
	// Build creates a new instance of T
	Build() (T, error)
}

Builder defines the interface for building instances with optional configuration and dependencies.

type ContextFunc added in v0.2.13

type ContextFunc[T any, C any] func(ctx context.Context, config C, opts ...options.Option) (T, error)

ContextFunc is a function that creates an instance of T with context support using the provided context, configuration and options.

func (ContextFunc[T, C]) New added in v0.2.13

func (f ContextFunc[T, C]) New(ctx context.Context, config C, opts ...options.Option) (T, error)

type CtxFuncRegistry added in v0.2.13

type CtxFuncRegistry[T any, C any] struct {
	Registry[ContextFunc[T, C]]
}

CtxFuncRegistry is a specialized registry for context-aware factory functions

func NewCtxFuncRegistry added in v0.2.13

func NewCtxFuncRegistry[T any, C any]() *CtxFuncRegistry[T, C]

NewCtxFuncRegistry creates a new CtxFuncRegistry

func (*CtxFuncRegistry[T, C]) Create added in v0.2.13

func (r *CtxFuncRegistry[T, C]) Create(ctx context.Context, name string, config C, opts ...options.Option) (T, error)

Create creates a new instance using the context-aware factory registered with the given name

type ErrFactoryNotFound added in v0.2.13

type ErrFactoryNotFound struct {
	Name string
}

ErrFactoryNotFound is returned when a requested factory is not found

func (ErrFactoryNotFound) Error added in v0.2.13

func (e ErrFactoryNotFound) Error() string

Error implements error interface

func (ErrFactoryNotFound) Is added in v0.2.13

func (e ErrFactoryNotFound) Is(target error) bool

Is implements the interface used by errors.Is

type Func added in v0.2.13

type Func[T any, C any] func(config C, opts ...options.Option) (T, error)

Func is a function that creates an instance of T using the provided configuration and options.

func (Func[T, C]) New added in v0.2.13

func (f Func[T, C]) New(config C, opts ...options.Option) (T, error)

type FuncRegistry added in v0.2.13

type FuncRegistry[T any, C any] struct {
	Registry[Func[T, C]]
}

FuncRegistry is a specialized registry for factory functions that create instances of type T using configuration of type C.

func NewFuncRegistry added in v0.2.13

func NewFuncRegistry[T any, C any]() *FuncRegistry[T, C]

NewFuncRegistry creates a new FuncRegistry

func (*FuncRegistry[T, C]) Create added in v0.2.13

func (r *FuncRegistry[T, C]) Create(name string, config C, opts ...options.Option) (T, error)

Create creates a new instance using the factory registered with the given name

type Registry

type Registry[F any] interface {
	// Get retrieves a factory by name
	Get(name string) (F, bool)
	// Register adds or updates a factory with the given name
	Register(name string, factory F)
	// RegisteredFactories returns all registered factories
	RegisteredFactories() map[string]F
	// Reset removes all registered factories
	Reset()
}

Registry defines the interface for managing factory functions. It allows for registering and retrieving factory functions by name.

type RegistryBuilder added in v0.2.13

type RegistryBuilder[T any, C any] struct {
	Registry[func() Builder[T, C]]
}

RegistryBuilder is a specialized registry for builders that create instances of type T using configuration of type C.

func NewRegistryBuilder added in v0.2.13

func NewRegistryBuilder[T any, C any]() *RegistryBuilder[T, C]

NewRegistryBuilder creates a new RegistryBuilder

func (*RegistryBuilder[T, C]) Create added in v0.2.13

func (r *RegistryBuilder[T, C]) Create(name string, config C, opts ...options.Option) (T, error)

Create creates a new instance using the builder registered with the given name

func (*RegistryBuilder[T, C]) CreateBuilder added in v0.2.13

func (r *RegistryBuilder[T, C]) CreateBuilder(name string) (Builder[T, C], error)

CreateBuilder creates a new builder using the factory registered with the given name

Jump to

Keyboard shortcuts

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