adapters

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 1 Imported by: 1

Documentation

Index

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

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

NewRegistry creates an empty adapter registry.

func (*Registry[T]) Clear

func (r *Registry[T]) Clear()

Clear removes all adapters.

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

func (r *Registry[T]) Get(name string) (T, bool)

Get retrieves an adapter by name.

Returns:

The adapter and true if found, otherwise zero value and false.

func (*Registry[T]) Has

func (r *Registry[T]) Has(name string) bool

Has checks if an adapter is registered.

func (*Registry[T]) MustGet

func (r *Registry[T]) MustGet(name string) T

MustGet retrieves an adapter and panics if not found.

func (*Registry[T]) Names

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

Names returns all registered adapter names.

func (*Registry[T]) Register

func (r *Registry[T]) Register(name string, adapter T)

Register adds an adapter with the given name.

func (*Registry[T]) Remove

func (r *Registry[T]) Remove(name string)

Remove unregisters an adapter.

func (*Registry[T]) SetDefault

func (r *Registry[T]) SetDefault(name string)

SetDefault sets the default adapter name.

Jump to

Keyboard shortcuts

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