Documentation
¶
Index ¶
- type Registry
- func (r *Registry[T]) Clear()
- func (r *Registry[T]) Default() T
- func (r *Registry[T]) DefaultOr(fallback T) T
- func (r *Registry[T]) Get(name string) (T, bool)
- func (r *Registry[T]) Has(name string) bool
- func (r *Registry[T]) MustGet(name string) T
- func (r *Registry[T]) Names() []string
- func (r *Registry[T]) OnRegister(fn func(name string, adapter T))
- func (r *Registry[T]) OnRemove(fn func(name string))
- func (r *Registry[T]) Register(name string, adapter T)
- func (r *Registry[T]) Remove(name string)
- func (r *Registry[T]) SetDefault(name string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Registry ¶
type Registry[T any] struct { // contains filtered or unexported fields }
Registry provides a generic, thread-safe registry for pluggable adapters.
Example:
r := adapters.NewRegistry[Store]()
r.Register("memory", NewMemoryStore())
r.SetDefault("memory")
func NewRegistry ¶
NewRegistry creates an empty adapter registry.
func (*Registry[T]) Default ¶
func (r *Registry[T]) Default() T
Default returns the default adapter.
Notes:
Panics if no default is set or default is not registered.
func (*Registry[T]) DefaultOr ¶
func (r *Registry[T]) DefaultOr(fallback T) T
DefaultOr returns the default adapter, or the provided fallback if no default is set.
func (*Registry[T]) Get ¶
Get retrieves an adapter by name.
Returns:
The adapter and true if found, otherwise zero value and false.
func (*Registry[T]) OnRegister ¶ added in v1.0.0
OnRegister registers a callback that fires when an adapter is registered.
func (*Registry[T]) OnRemove ¶ added in v1.0.0
OnRemove registers a callback that fires when an adapter is removed.
func (*Registry[T]) SetDefault ¶
SetDefault sets the default adapter name.
Click to show internal directories.
Click to hide internal directories.