registry

package
v0.27.0 Latest Latest
Warning

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

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

Documentation

Overview

Package registry provides a generic, domain-agnostic name→constructor registry. It lets a low-level package expose a lookup-by-name facility without depending on the high-level types being constructed: concrete constructors are bound at the composition root. The type parameter T is a generic constraint, not a dynamically-typed value, mirroring the existing llm.StreamReader[T any] precedent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DuplicateNameError

type DuplicateNameError struct{ Name string }

DuplicateNameError is returned by Registry.Register when a name is already bound to a constructor. It is a leaf error carrying the offending name; callers may errors.As to inspect it. Registration fails secure (the existing binding is never overwritten).

func (DuplicateNameError) Error

func (e DuplicateNameError) Error() string

type Registry

type Registry[T any] struct {
	// contains filtered or unexported fields
}

Registry maps a name to a constructor that builds a value of type T. The zero Registry is not usable; construct one with New so the backing map is initialized.

func New

func New[T any]() *Registry[T]

New returns an empty Registry ready for Register and Open.

func (*Registry[T]) Names

func (r *Registry[T]) Names() []string

Names returns the registered names sorted ascending. The result is a fresh slice; mutating it does not affect the registry.

func (*Registry[T]) Open

func (r *Registry[T]) Open(ctx context.Context, name string) (T, error)

Open constructs the value bound to name. If name was never registered it returns the zero T and a *UnknownNameError whose Known field lists the registered names in ascending order. If the constructor itself fails, Open returns the zero T and the constructor's error unchanged.

func (*Registry[T]) Register

func (r *Registry[T]) Register(name string, f func(context.Context) (T, error)) error

Register binds name to a constructor. If name is already registered, the existing binding is preserved and a *DuplicateNameError is returned (fail secure — no overwrite).

type UnknownNameError

type UnknownNameError struct {
	Name  string
	Known []string
}

UnknownNameError is returned by Registry.Open when a name was never registered. Known lists the registered names in ascending order so callers can surface valid choices. It is a leaf error with context fields and is errors.As-able.

func (UnknownNameError) Error

func (e UnknownNameError) Error() string

Jump to

Keyboard shortcuts

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