registry

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: GPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeNotFound errors.GoCode = "NotFound"
)

Variables

View Source
var (
	ErrNotFound errors.AbstractError[errors.Error] = errors.New(CodeNotFound, "not found")
)
View Source
var METHODS = NewMethods(512)

Functions

func For

func For(rv reflect.Value, methodNames []string, validChk ...func(reflect.Value, *reflect.Method) error) (rec reflect.Value, rm *reflect.Method, err error)

func GetDefault

func GetDefault[T any](types map[any]T, key RegKey[reflect.Type], kindKey RegKey[reflect.Kind]) (obj T, found bool)

func GetKind

func GetKind[T any](types map[any]T, _ RegKey[reflect.Type], kindKey RegKey[reflect.Kind]) (obj T, found bool)

func GetKindDst

func GetKindDst[T any](types map[any]T, _ RegKey[reflect.Type], kindKey RegKey[reflect.Kind]) (obj T, found bool)

func GetKindSrc

func GetKindSrc[T any](types map[any]T, _ RegKey[reflect.Type], kindKey RegKey[reflect.Kind]) (obj T, found bool)

func GetType

func GetType[T any](types map[any]T, key RegKey[reflect.Type], _ RegKey[reflect.Kind]) (obj T, found bool)

func GetTypeDst

func GetTypeDst[T any](types map[any]T, key RegKey[reflect.Type], _ RegKey[reflect.Kind]) (obj T, found bool)

func GetTypeSrc

func GetTypeSrc[T any](types map[any]T, key RegKey[reflect.Type], _ RegKey[reflect.Kind]) (obj T, found bool)

Types

type Flag

type Flag bitcheck.Flag
const (
	NONE        Flag = iota
	EXACT_IFACE Flag = iota << 1
	NOTFOUND_REG
)

type Getter

type Getter[T any] = func(types map[any]T, key RegKey[reflect.Type], kindKey RegKey[reflect.Kind]) (T, bool)

type MethodsRegistry

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

func NewMethods

func NewMethods(initSize int) *MethodsRegistry

func (*MethodsRegistry) CoolDown

func (m *MethodsRegistry) CoolDown()

Clears the cache and returns the total count of cleared items

func (*MethodsRegistry) For

func (m *MethodsRegistry) For(rv reflect.Value, methodNames []string, validChk ...func(reflect.Value, *reflect.Method) error) (rec reflect.Value, rm *reflect.Method, err error)

Look for multiple methods for this type, cache the first one found for future uses.

This cache cannot store multiple methods per type, and will always yield the cached result.

type RegKey

type RegKey[T any] struct {
	Dst T
	Src T
}

type TypeRegistry

type TypeRegistry[T any] struct {
	// contains filtered or unexported fields
}

func NewTypeRegistry

func NewTypeRegistry[T any](lock sync.Locker, flags Flag, get func(dst, src reflect.Type) []Getter[T]) *TypeRegistry[T]

func (*TypeRegistry[T]) Clear

func (reg *TypeRegistry[T]) Clear() int

func (*TypeRegistry[T]) Clone

func (reg *TypeRegistry[T]) Clone() *TypeRegistry[T]

func (*TypeRegistry[T]) Get

func (reg *TypeRegistry[T]) Get(dstTyp reflect.Type, srcTyp reflect.Type) (obj T, found bool)

func (*TypeRegistry[T]) InterfaceRegister

func (reg *TypeRegistry[T]) InterfaceRegister(iface reflect.Type, scan T) (overwrite bool)

func (*TypeRegistry[T]) Register

func (reg *TypeRegistry[T]) Register(dstType reflect.Type, srcOrT ...any) (overwrite bool)

func (*TypeRegistry[T]) RegisterKind

func (reg *TypeRegistry[T]) RegisterKind(dstKind, srcKind reflect.Kind, checker T) (overwrite bool)

func (*TypeRegistry[T]) WithLock

func (reg *TypeRegistry[T]) WithLock(l sync.Locker)

Jump to

Keyboard shortcuts

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