Documentation
¶
Overview ¶
Package provider implements a generic provider framework using Go generics for swappable backends with runtime switching capabilities.
It provides a registry for managing multiple provider implementations with factory-based instantiation, availability checking, and runtime selection.
Usage ¶
reg := provider.NewRegistry[MyProvider]()
reg.Register("default", myFactory)
p, err := reg.Get("default")
This package is used by gokit's provider-pattern modules (llm, transcription, diarization) for pluggable backend support.
Index ¶
- type Factory
- type HealthCheckSelector
- type Manager
- func (m *Manager[T]) Available() []string
- func (m *Manager[T]) Get(ctx context.Context) (T, error)
- func (m *Manager[T]) GetByName(name string) (T, error)
- func (m *Manager[T]) Initialize(name string, cfg map[string]any) error
- func (m *Manager[T]) Register(name string, factory Factory[T])
- func (m *Manager[T]) SetDefault(name string) error
- type PrioritySelector
- type Provider
- type Registry
- type RoundRobinSelector
- type Selector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HealthCheckSelector ¶
type HealthCheckSelector[T Provider] struct{}
HealthCheckSelector picks the first available provider by calling IsAvailable.
type Manager ¶
type Manager[T Provider] struct { // contains filtered or unexported fields }
Manager provides the main API for working with providers, combining a Registry for storage and a Selector for choosing providers.
func NewManager ¶
NewManager creates a Manager backed by the given registry and selector.
func (*Manager[T]) Initialize ¶
Initialize creates a provider from its factory and stores it for use.
func (*Manager[T]) SetDefault ¶
SetDefault sets the default provider by name.
type PrioritySelector ¶
type PrioritySelector[T Provider] struct { // Priority is the ordered list of provider names to try. Priority []string }
PrioritySelector tries providers in the given priority order and returns the first one that is available.
type Provider ¶
type Provider interface {
// Name returns the provider's unique name.
Name() string
// IsAvailable checks if the provider is ready to handle requests.
IsAvailable(ctx context.Context) bool
}
Provider is the base interface all providers must implement.
type Registry ¶
type Registry[T Provider] struct { // contains filtered or unexported fields }
Registry manages named provider factories and cached instances.
func NewRegistry ¶
NewRegistry creates a new empty Registry.
func (*Registry[T]) RegisterFactory ¶
RegisterFactory registers a named factory for creating providers.
type RoundRobinSelector ¶
type RoundRobinSelector[T Provider] struct { // contains filtered or unexported fields }
RoundRobinSelector distributes requests across providers.