Help us shape the future of Go! Take the 2026 Go Developer Survey

component

package
v1.11.9 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError returns true if the error is a NamedRegistrationNotFound or RegistrationNotFound error.

Types

type NameBasedRegistration

type NameBasedRegistration[V, MD any] struct {
	Name     string
	Value    V
	Metadata MD
}

NameBasedRegistration associates a name (key) with a value and optional metadata. The value and metadata can be anything, including a function (often a factory function).

Type parameters: - V: the type stored in the registry - MV: the type of metadata stored in the registry

type NameBasedRegistry

type NameBasedRegistry[V, MD any] interface {
	// Register adds a new registration to the registry.
	Register(NameBasedRegistration[V, MD]) error
	// MustRegister adds a new registration to the registry and panics if any
	// error is encountered.
	MustRegister(NameBasedRegistration[V, MD])
	// Get returns the registration matching the provided name (key) or, if none
	// is found, an empty registration and a NamedRegistrationNotFoundError.
	Get(string) (NameBasedRegistration[V, MD], error)
}

NameBasedRegistry provides methods for registering and retrieving values and optional metadata by name (key). The value can be anything, including a function (often a factory function).

func MustNewNameBasedRegistry

func MustNewNameBasedRegistry[V, MD any](
	opts *NameBasedRegistryOptions,
	registrations ...NameBasedRegistration[V, MD],
) NameBasedRegistry[V, MD]

Must NewNameBasedRegistry returns a default implementation of the NameBasedRegistry interface. Optional initial registrations may be provided when calling this function. This function panics if any error is encountered.

func NewNameBasedRegistry

func NewNameBasedRegistry[V, MD any](
	opts *NameBasedRegistryOptions,
	registrations ...NameBasedRegistration[V, MD],
) (NameBasedRegistry[V, MD], error)

NewNameBasedRegistry returns a default implementation of the NameBasedRegistry interface. Optional initial registrations may be provided when calling this function.

type NameBasedRegistryOptions

type NameBasedRegistryOptions struct {
	// AllowOverwriting indicates whether existing registrations may be
	// overwritten with new ones. When this is false, an attempt to overwrite an
	// existing registration produces an error.
	AllowOverwriting bool
}

NameBasedRegistryOptions represents configuration options for a NameBasedRegistry.

type NamedRegistrationNotFoundError

type NamedRegistrationNotFoundError struct {
	Name string
}

NamedRegistrationNotFoundError is an error returned when a registration cannot be found in a name-based registry.

func (NamedRegistrationNotFoundError) Error

type Predicate

type Predicate[A any] interface {
	~func(context.Context, A) (bool, error)
}

Predicate is a constraint for functions that evaluate whether a given input of type A matches certain criteria. Predicates return true if the input matches, false otherwise, and may return an error if evaluation fails.

type PredicateBasedRegistration

type PredicateBasedRegistration[PA any, P Predicate[PA], V, MD any] struct {
	Predicate P
	Value     V
	Metadata  MD
}

PredicateBasedRegistration associates a predicate function with a value and optional metadata. The value and metadata can be anything, including a function (often a factory function).

Type parameters: - PA: the input type for the predicate - P: the predicate function type (must satisfy Predicate[PA]) - V: the type stored in the registry - MV: the type of metadata stored in the registry

type PredicateBasedRegistry

type PredicateBasedRegistry[PA any, P Predicate[PA], V, MD any] interface {
	// Register adds a new registration to the registry.
	Register(PredicateBasedRegistration[PA, P, V, MD]) error
	// MustRegister adds a new registration to the registry and panics if any
	// error is encountered.
	MustRegister(PredicateBasedRegistration[PA, P, V, MD])
	// Get searches for a matching registration by evaluating each registration's
	// predicate against the provided input. Returns the first matching
	// registration, or if none is found, an empty registration and a
	// RegistrationNotFoundError.
	Get(context.Context, PA) (
		PredicateBasedRegistration[PA, P, V, MD],
		error,
	)
	// GetAll searches for all matching registrations by evaluating each
	// registration's predicate against the provided input. Returns all matching
	// registrations, or an empty slice if none match.
	GetAll(context.Context, PA) (
		[]PredicateBasedRegistration[PA, P, V, MD],
		error,
	)
}

PredicateBasedRegistry provides methods for registering and retrieving values and metadata based on predicate evaluation.

Type parameters match those of Registration.

func MustNewPredicateBasedRegistry

func MustNewPredicateBasedRegistry[PA any, P Predicate[PA], V, MD any](
	registrations ...PredicateBasedRegistration[PA, P, V, MD],
) PredicateBasedRegistry[PA, P, V, MD]

MustNewPredicateBasedRegistry returns a default implementation of the PredicateBasedRegistry interface. Optional initial registrations may be provided when calling this function. This function panics if any error is encountered.

func NewPredicateBasedRegistry

func NewPredicateBasedRegistry[PA any, P Predicate[PA], V, MD any](
	registrations ...PredicateBasedRegistration[PA, P, V, MD],
) (PredicateBasedRegistry[PA, P, V, MD], error)

NewPredicateBasedRegistry returns a default implementation of the PredicateBasedRegistry interface. Optional initial registrations may be provided when calling this function.

type RegistrationNotFoundError

type RegistrationNotFoundError struct{}

RegistrationNotFoundError is an error returned when no matching registration can be found in a registry.

func (RegistrationNotFoundError) Error

Jump to

Keyboard shortcuts

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