cfg

package module
v0.0.0-...-6e4230c Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2016 License: MIT Imports: 2 Imported by: 0

README

Configuration helpers

Build Status Go Report Card GoDoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractUnmarshalFunc

func ExtractUnmarshalFunc(c Configurer, key string) func(interface{}) error

ExtractUnmarshalFunc is helper function used to create Unmarshaling function for provided key

func IsErrKeyMissing

func IsErrKeyMissing(e error) bool

IsErrKeyMissing returns true if provided error is instance of ErrKeyMissing

Types

type Configurer

type Configurer interface {
	// Has returns true if configurer has requested field
	Has(string) bool

	// UnmarshalKey writes configuration value from string key into interface target
	UnmarshalKey(string, interface{}) error

	// KeyFunc return Unmarshaling function for requested key
	KeyFunc(string) func(interface{}) error
}

Configurer interface describes configuration source

func ErrConfigurer

func ErrConfigurer(err error) Configurer

ErrConfigurer builds configuration source, that will return an error on any action and false on Has invocation

func NewValidableConfig

func NewValidableConfig(source Configurer) Configurer

NewValidableConfig returns adapter for provided configurer, that runs Validate function on all returning configuration values if this value has Validate method

type ConfigurerWithAliases

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

ConfigurerWithAliases is special configurer adapter, that works with aliases

func NewConfigurationWithAliases

func NewConfigurationWithAliases(real Configurer) *ConfigurerWithAliases

NewConfigurationWithAliases creates new configurere with empty aliases list

func (*ConfigurerWithAliases) Alias

func (c *ConfigurerWithAliases) Alias(virtual, real string)

Alias registers new alias

func (ConfigurerWithAliases) Has

func (c ConfigurerWithAliases) Has(key string) bool

Has returns true if configurer has requested field

func (ConfigurerWithAliases) KeyFunc

func (c ConfigurerWithAliases) KeyFunc(key string) func(interface{}) error

KeyFunc return Unmarshaling function for requested key

func (ConfigurerWithAliases) UnmarshalKey

func (c ConfigurerWithAliases) UnmarshalKey(key string, target interface{}) error

UnmarshalKey writes configuration value from string key into interface target

func (ConfigurerWithAliases) Validate

func (c ConfigurerWithAliases) Validate() error

Validate performs validation of all configs inside list

type ErrKeyMissing

type ErrKeyMissing struct {
	Key string
}

ErrKeyMissing is special error, thrown when missing key is requested

func (ErrKeyMissing) Error

func (e ErrKeyMissing) Error() string

type List

type List []Configurer

List represents slice of configurers and is configurer by itself Configurers in list are processed backwards, so last one has maximum priority

func (List) Has

func (c List) Has(key string) bool

Has returns true if configurer has requested field

func (List) KeyFunc

func (c List) KeyFunc(key string) func(interface{}) error

KeyFunc return Unmarshaling function for requested key

func (List) UnmarshalKey

func (c List) UnmarshalKey(key string, target interface{}) error

UnmarshalKey writes configuration value from string key into interface target

func (List) Validate

func (c List) Validate() error

Validate performs validation of all configs inside list

type Map

type Map map[string]interface{}

Map is configuration provider, based on simple hash map

func (Map) Has

func (m Map) Has(key string) bool

Has returns true if configurer has requested field

func (Map) KeyFunc

func (m Map) KeyFunc(key string) func(interface{}) error

KeyFunc return Unmarshaling function for requested key

func (Map) UnmarshalKey

func (m Map) UnmarshalKey(key string, target interface{}) error

UnmarshalKey writes configuration value from string key into interface target

type Validable

type Validable interface {
	Validate() error
}

Validable interface describes entities, that are able to self-test internal data and return error if something wrong

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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