Documentation
¶
Index ¶
- func IsAvailableSafe(provider AvailabilityProvider, logger *slog.Logger, format string, ...) (available bool)
- func IsNil(v any) bool
- func LowerKey(name string) string
- func PanicText(rec any) string
- func Same(a, b any) bool
- func ScopeKey(ctx context.Context, scope string) string
- type API
- type AvailabilityProvider
- type Generation
- type NamedProvider
- type Options
- type ProviderTypeError
- type Registry
- func (r *Registry[P]) AllProviders() []P
- func (r *Registry[P]) Export() API[P]
- func (r *Registry[P]) GetProvider(ctx context.Context, name, scope string) P
- func (r *Registry[P]) ListProviders(ctx context.Context, scope string) []P
- func (r *Registry[P]) Merged(ctx context.Context, scope string) *pydict.Dict[string, P]
- func (r *Registry[P]) Register(provider P, scope string) error
- func (r *Registry[P]) RegistryGeneration(ctx context.Context, scope string) Generation
- func (r *Registry[P]) ResetForTests()
- func (r *Registry[P]) RestoreRegistration(name string, current, previous P, scope string) bool
- func (r *Registry[P]) Scoped() ScopedRegistry
- func (r *Registry[P]) SnapshotRegistration(name, scope string) P
- type ScopedRegistry
- type ValueError
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 ¶
Python None test of a provider value, true for nil and nil pointer, map, slice, func or channel values
func LowerKey ¶
Registry key of a name stripped of whitespace and lowercased for case insensitive registries
Types ¶
type API ¶
type API[P NamedProvider] struct { Providers *pydict.Dict[string, P] ScopedProviders *pydict.Dict[string, *pydict.Dict[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 ¶
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 }
Python TypeError a provider registry raises for an object that is not an instance of its provider class
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 ¶
Bound method values and live test hooks a registry module exposes under its historical names
func (*Registry[P]) GetProvider ¶
Provider registered under name in the active scope, then globally, the zero value when absent
func (*Registry[P]) ListProviders ¶
Every provider visible in the active scope sorted by name
func (*Registry[P]) Register ¶
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 ¶
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 ¶
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