Documentation
¶
Index ¶
- Variables
- type RangeFunc
- type Registry
- func (r *Registry[K, V]) Exists(key K) bool
- func (r *Registry[K, V]) Get(key K) (V, bool)
- func (r *Registry[K, V]) Length() int
- func (r *Registry[K, V]) MustRegister(key K, val V)
- func (r *Registry[K, V]) Overwrite(key K, val V)
- func (r *Registry[K, V]) Range(f RangeFunc[K, V]) error
- func (r *Registry[K, V]) Register(key K, val V) error
- func (r *Registry[K, V]) Unregister(key K)
Constants ¶
This section is empty.
Variables ¶
var ErrContinue = errors.New("continue iteration")
ErrContinue is a no-op error, which is used to signal Registry.Range to continue the iteration.
var ErrKeyAlreadyRegistered = errors.New("key is already registered")
ErrKeyAlreadyRegistered is returned when attempting to register a key, which is already present in the registry.
var ErrStopIteration = errors.New("stop iteration")
ErrStopIteration is an error, which is used to stop iterating over the registry.
var ModelRegistry = New[string, any]()
ModelRegistry is the default registry for models.
var ScheduledTaskRegistry = New[string, *asynq.Task]()
ScheduledTaskRegistry is the default registry for scheduled tasks.
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 { // contains filtered or unexported fields }
Registry is a concurrent-safe registry.
func (*Registry[K, V]) Exists ¶
Exists returns a boolean indicating whether the given key exists in the registry.
func (*Registry[K, V]) Get ¶
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]) 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 ¶
Range calls f for each item in the registry. If f returns an error, Range will stop the iteration.
func (*Registry[K, V]) Unregister ¶
func (r *Registry[K, V]) Unregister(key K)
Unregister removes the key (if present) from the registry.