registry

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package registry provides a thread-safe registry for storing and retrieving values of types via a string key. It ensures that each type is registered only once and provides error handling for duplicate registrations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(name string, args ...interface{}) (any, error)

Get retrieves value with provide type name from the registry.

func Register

func Register(a any) error

Register stores a type in the registry. It returns an error if the type is already registered, or if the type does not implement the Named interface and cannot be registered.

To register, a value of a type is provided. Implementing the Newable interface allows the registry to create and initialize a new value of the type for you based on the provided args, otherwise any initialization must be done manually.

Types

type ErrTypeAlreadyRegistered

type ErrTypeAlreadyRegistered struct{ Name string }

ErrObjectAlreadyRegistered is an error that is returned when a type is registered more than once.

func (ErrTypeAlreadyRegistered) Error

func (e ErrTypeAlreadyRegistered) Error() string

Error returns the error message.

func (ErrTypeAlreadyRegistered) Is

Is returns true if the error is of type ErrTypeAlreadyRegistered.

type ErrTypeNotRegistered

type ErrTypeNotRegistered struct{ Name string }

ErrTypeDoesNotExist is an error that is returned when a type is not found in the registry.

func (ErrTypeNotRegistered) Error

func (e ErrTypeNotRegistered) Error() string

Error returns the error message.

func (ErrTypeNotRegistered) Is

func (e ErrTypeNotRegistered) Is(err error) bool

Is returns true if the error is of type ErrTypeNotRegistered.

type Named

type Named interface {
	Name() string
}

Named is an interface that provides a method to return the name of a type.

type Newable

type Newable interface {
	New(...interface{}) (any, error)
}

Newable is an interface that provides a method to create a fresh value of a type.

type SafeMap

type SafeMap struct {
	// contains filtered or unexported fields
}

SafeMap is a thread-safe map that stores any type of value.

func NewSafeMap

func NewSafeMap() *SafeMap

NewSafeMap creates a new SafeMap.

func (*SafeMap) Get

func (s *SafeMap) Get(key string) (any, bool)

Get retrieves a value from the map.

func (*SafeMap) Set

func (s *SafeMap) Set(key string, value any)

Set stores a value in the map.

Jump to

Keyboard shortcuts

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