Documentation
¶
Index ¶
- func IsNotFoundError(err error) bool
- type NameBasedRegistration
- type NameBasedRegistry
- type NameBasedRegistryOptions
- type NamedRegistrationNotFoundError
- type Predicate
- type PredicateBasedRegistration
- type PredicateBasedRegistry
- func MustNewPredicateBasedRegistry[PA any, P Predicate[PA], V, MD any](registrations ...PredicateBasedRegistration[PA, P, V, MD]) PredicateBasedRegistry[PA, P, V, MD]
- func NewPredicateBasedRegistry[PA any, P Predicate[PA], V, MD any](registrations ...PredicateBasedRegistration[PA, P, V, MD]) (PredicateBasedRegistry[PA, P, V, MD], error)
- type RegistrationNotFoundError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNotFoundError ¶
IsNotFoundError returns true if the error is a NamedRegistrationNotFound or RegistrationNotFound error.
Types ¶
type NameBasedRegistration ¶
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 ¶
func (e NamedRegistrationNotFoundError) Error() string
type Predicate ¶
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, ) }
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 ¶
func (e RegistrationNotFoundError) Error() string