providerregistry

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAvailableSafe

func IsAvailableSafe(provider AvailabilityProvider, logger *slog.Logger, format string, level slog.Level, excInfo bool) (available bool)

Availability of a provider, a panicking probe reading as unavailable and logged at level with its traceback when excInfo

func IsNil

func IsNil(v any) bool

Python None test of a provider value, true for nil and nil pointer, map, slice, func or channel values

func LowerKey

func LowerKey(name string) string

Registry key of a name stripped of whitespace and lowercased for case insensitive registries

func PanicText

func PanicText(rec any) string

Python str of a recovered panic value

func Same

func Same(a, b any) bool

Python identity test of two provider values, reference kinds compared by pointer and other comparable values by equality

func ScopeKey

func ScopeKey(ctx context.Context, scope string) string

Read scope key, the active home key when scope is empty

Types

type API

type API[P NamedProvider] struct {
	Providers            *orderedutil.Map[string, P]
	ScopedProviders      *orderedutil.Map[string, *orderedutil.Map[string, P]]
	Lock                 *sync.Mutex
	RegisterProvider     func(provider P, scope string) error
	ListProviders        func(ctx context.Context, scope string) []P
	GetProvider          func(ctx context.Context, name, scope string) P
	SnapshotRegistration func(name, scope string) P
	RestoreRegistration  func(name string, current, previous P, scope string) bool
	RegistryGeneration   func(ctx context.Context, scope string) Generation
	ResetForTests        func()
}

Historical module level API of a provider registry module plus its providers, scoped providers and lock test hooks

type AvailabilityProvider

type AvailabilityProvider interface {
	NamedProvider
	IsAvailable() bool
}

Provider whose availability probe is_available_safe guards

type Generation

type Generation struct {
	Global int
	Scoped int
}

Cache fingerprint of a registry, the global generation and the active scope generation

type NamedProvider

type NamedProvider interface {
	Name() string
}

Abstract identity every registered provider implements, the stable lowercase config key value

type Options

type Options struct {
	Label              string
	Logger             *slog.Logger
	Normalize          func(string) string
	BuiltinNames       map[string]bool
	OnBuiltinCollision func(key string) error
	// Python class name of the provider base, the Go type name when empty
	ProviderCls string
}

Construction options of a provider registry, Normalize defaulting to whitespace stripping

type ProviderTypeError

type ProviderTypeError struct{ Message string }

Error a provider registry returns for a value that is not of its provider type, naming both types

func (*ProviderTypeError) Error

func (e *ProviderTypeError) Error() string

type Registry

type Registry[P NamedProvider] struct {
	Label        string
	ProviderCls  string
	Logger       *slog.Logger
	Normalize    func(string) string
	BuiltinNames map[string]bool
	// contains filtered or unexported fields
}

Global and per profile scope provider maps with plugin snapshot and restore support

func New

func New[P NamedProvider](opts Options) *Registry[P]

Registry for providers of type P, an all uppercase label keeping its case in log lines

func (*Registry[P]) AllProviders

func (r *Registry[P]) AllProviders() []P

Every provider of every layer, the global map first and then each scope map in registration order

func (*Registry[P]) Export

func (r *Registry[P]) Export() API[P]

Bound method values and live test hooks a registry module exposes under its historical names

func (*Registry[P]) GetProvider

func (r *Registry[P]) GetProvider(ctx context.Context, name, scope string) P

Provider registered under name in the active scope, then globally, the zero value when absent

func (*Registry[P]) ListProviders

func (r *Registry[P]) ListProviders(ctx context.Context, scope string) []P

Every provider visible in the active scope sorted by name

func (*Registry[P]) Merged

func (r *Registry[P]) Merged(ctx context.Context, scope string) *orderedutil.Map[string, P]

Copy of the global map overlaid with the active profile scope map

func (*Registry[P]) Register

func (r *Registry[P]) Register(provider P, scope string) error

Registers a provider in the global layer or a scope, same name re-registration overwriting for hot reload

func (*Registry[P]) RegistryGeneration

func (r *Registry[P]) RegistryGeneration(ctx context.Context, scope string) Generation

Global and active scope generation pair callers compare to invalidate caches

func (*Registry[P]) ResetForTests

func (r *Registry[P]) ResetForTests()

Clears every registration and advances the global generation, for tests only

func (*Registry[P]) RestoreRegistration

func (r *Registry[P]) RestoreRegistration(name string, current, previous P, scope string) bool

Restores previous, or removes the slot for a nil previous, only while current still occupies it

func (*Registry[P]) Scoped

func (r *Registry[P]) Scoped() ScopedRegistry

Plugin context view of the registry that register category provider methods drive

func (*Registry[P]) SnapshotRegistration

func (r *Registry[P]) SnapshotRegistration(name, scope string) P

Exact slot occupant with no global fallback, the zero value when the slot is empty

type ScopedRegistry

type ScopedRegistry interface {
	Accepts(provider any) bool
	ProviderName(provider any) string
	Identity(provider any) error
	Snapshot(name, scope string) any
	Register(provider any, scope string) (bool, error)
	Restore(name string, current, replacement any, scope string) bool
}

Untyped registry view the plugin context register category provider methods drive

type ValueError

type ValueError struct{ Message string }

Python ValueError a registry or provider raises for a well typed but unacceptable value

func (*ValueError) Error

func (e *ValueError) Error() string

Jump to

Keyboard shortcuts

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