builder

package
v0.2.19 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 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

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

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

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

type CtxFuncRegistry

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

CtxFuncRegistry is a specialized registry for context-aware factory functions

func NewCtxFuncRegistry

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

NewCtxFuncRegistry creates a new CtxFuncRegistry

func (*CtxFuncRegistry[T, C]) Create

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

type ErrFactoryNotFound struct {
	Name string
}

ErrFactoryNotFound is returned when a requested factory is not found

func (ErrFactoryNotFound) Error

func (e ErrFactoryNotFound) Error() string

Error implements error interface

func (ErrFactoryNotFound) Is

func (e ErrFactoryNotFound) Is(target error) bool

Is implements the interface used by errors.Is

type Func

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

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

type FuncRegistry

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

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

NewFuncRegistry creates a new FuncRegistry

func (*FuncRegistry[T, C]) Create

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

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

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

NewRegistryBuilder creates a new RegistryBuilder

func (*RegistryBuilder[T, C]) Create

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

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