registry

package
v0.0.0-...-76fafce Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() *registry

func Register

func Register(reg Registry, v Registrable, s Serializer, d Deserializer, os []BuildOption) error

func RegisterFactory

func RegisterFactory(reg Registry, key string, fn func() interface{}, s Serializer, d Deserializer,
	os []BuildOption,
) error

func RegisterKey

func RegisterKey(reg Registry, key string, v interface{}, s Serializer, d Deserializer, os []BuildOption) error

Types

type AlreadyRegisteredKey

type AlreadyRegisteredKey string

func (AlreadyRegisteredKey) Error

func (key AlreadyRegisteredKey) Error() string

type BuildOption

type BuildOption func(v interface{}) error

func ValidateImplements

func ValidateImplements(checkV interface{}) BuildOption

ValidateImplements will verify that the built value implements the given interface

Pass interfaces using "(*I)(nil)", like in this example:

type MyInterface interface {
    MyMethod(int) bool
}

ValidateImplements((*MyInterface)(nil))

You will only be able to validate interfaces with exported methods, you will not be able to validate any that have one or more unexported methods.

type Deserializer

type Deserializer func(d []byte, v interface{}) error

type Registrable

type Registrable interface {
	Key() string
}

type Registry

type Registry interface {
	Serialize(key string, v interface{}) ([]byte, error)
	MustSerialize(key string, v interface{}) []byte
	Build(key string, options ...BuildOption) (interface{}, error)
	MustBuild(key string, options ...BuildOption) interface{}
	Deserialize(key string, data []byte, options ...BuildOption) (interface{}, error)
	MustDeserialize(key string, data []byte, options ...BuildOption) interface{}
	// contains filtered or unexported methods
}

type Serde

type Serde interface {
	Register(v Registrable, options ...BuildOption) error
	RegisterKey(key string, v interface{}, options ...BuildOption) error
	RegisterFactory(key string, fn func() interface{}, options ...BuildOption) error
}

type Serializer

type Serializer func(v interface{}) ([]byte, error)

type UnregisteredKey

type UnregisteredKey string

func (UnregisteredKey) Error

func (key UnregisteredKey) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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