registry

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package registry provides a simple container for values in the application space. TODO: check if we should use sliceutil or maputil for exists or prefixed entries.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownEntry       = "registry: unknown registry name %#v, maybe you forgot to set it"
	ErrMandatoryArguments = errors.New("registry: one or more arguments have a zero-value")
	ErrAlreadyExists      = "registry: %v is already registered"
)

Error messages

Functions

func Get

func Get(name string) (interface{}, error)

Get returns the value by the registered name. If the registry name does not exist, an error will return.

func Prefix

func Prefix(prefix string) map[string]interface{}

Prefix returns all entries as map which name start with the given prefix. If none was found, nil map will return.

func Set

func Set(name string, value interface{}) error

Set a value by name. The name and value argument must have a non-zero value, and the registered name must be unique. If a validator is registered, and the name matches any prefix, it will be checked before the value will be added to the registry.

func Validator

func Validator(validate Validate) error

Validator provides an opportunity to add a custom function before the value is added to the registry.

Types

type Validate

type Validate struct {
	Prefix string
	Fn     func(string, interface{}) error
}

Validate defines a prefix and custom function which can be added to the `Validator` function. The custom function will receive the registry name and registry value as arguments.

Jump to

Keyboard shortcuts

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