Help us shape the future of Go! Take the 2026 Go Developer Survey

registry

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2025 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrContinue = errors.New("continue iteration")

ErrContinue is a no-op error, which is used to signal Registry.Range to continue the iteration.

View Source
var ErrKeyAlreadyRegistered = errors.New("key is already registered")

ErrKeyAlreadyRegistered is returned when attempting to register a key, which is already present in the registry.

View Source
var ErrStopIteration = errors.New("stop iteration")

ErrStopIteration is an error, which is used to stop iterating over the registry.

View Source
var ModelRegistry = New[string, any]()

ModelRegistry is the default registry for models.

View Source
var ScheduledTaskRegistry = New[string, *asynq.Task]()

ScheduledTaskRegistry is the default registry for scheduled tasks.

View Source
var TaskRegistry = New[string, asynq.Handler]()

TaskRegistry is the default registry for tasks.

Functions

This section is empty.

Types

type RangeFunc

type RangeFunc[K comparable, V any] func(key K, val V) error

RangeFunc is a function which is called when iterating over the registry items. In order to stop iteration callers should return ErrStopIteration.

type Registry

type Registry[K comparable, V any] struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Registry is a concurrent-safe registry.

func New

func New[K comparable, V any]() *Registry[K, V]

New creates a new empty registry.

func (*Registry[K, V]) Exists

func (r *Registry[K, V]) Exists(key K) bool

Exists returns a boolean indicating whether the given key exists in the registry.

func (*Registry[K, V]) Get

func (r *Registry[K, V]) Get(key K) (V, bool)

Get returns the value associated with the given key and a boolean indicating whether the key is present in the registry.

func (*Registry[K, V]) Length

func (r *Registry[K, V]) Length() int

Length returns the number of items in the registry.

func (*Registry[K, V]) MustRegister

func (r *Registry[K, V]) MustRegister(key K, val V)

MustRegister registers the key and value, or panics in case of errors.

func (*Registry[K, V]) Overwrite

func (r *Registry[K, V]) Overwrite(key K, val V)

Overwrite replaces the key specified by K with the value V in the registry.

func (*Registry[K, V]) Range

func (r *Registry[K, V]) Range(f RangeFunc[K, V]) error

Range calls f for each item in the registry. If f returns an error, Range will stop the iteration.

func (*Registry[K, V]) Register

func (r *Registry[K, V]) Register(key K, val V) error

Register registers the key and value with the registry

func (*Registry[K, V]) Unregister

func (r *Registry[K, V]) Unregister(key K)

Unregister removes the key (if present) from the registry.

Jump to

Keyboard shortcuts

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