Documentation ¶
Index ¶
- Constants
- Variables
- func Postprocess(c Config, options ...PostprocessOption) error
- func TreePathString(t Tree) string
- type Config
- type Container
- func (r *Container) Clone() (Config, error)
- func (r *Container) Copy(v Config) error
- func (r *Container) DeepClone() (Config, error)
- func (r *Container) DeepCopy(v Config) error
- func (r *Container) Default() error
- func (r *Container) Empty()
- func (r *Container) EmptyClone() Config
- func (r *Container) Expand() error
- func (r *Container) Path(path string) (Config, error)
- func (r *Container) Replace(c Config)
- func (r *Container) Unwrap() Config
- func (r *Container) Validate() error
- type Defaultable
- type DestinationOption
- type ErrFileNotFound
- type ErrMarshal
- type ErrPathNotFound
- type ErrPostprocess
- type ErrUnexpectedKind
- type ErrUnexpectedScheme
- type ErrUnmarshal
- type Expandable
- type Marshaler
- type PostprocessOption
- type SourceOption
- type Tree
- type TreeArrayFieldNode
- type TreeMapFieldNode
- type TreeNode
- func (n *TreeNode) Interface() interface{}
- func (n *TreeNode) Name() string
- func (n *TreeNode) Next() []Tree
- func (n *TreeNode) Previous() Tree
- func (n *TreeNode) Value() reflect.Value
- func (n *TreeNode) WithNext(t Tree) Tree
- func (n *TreeNode) WithPrevious(t Tree) Tree
- func (n *TreeNode) WithValue(v reflect.Value) Tree
- type TreeSliceFieldNode
- type TreeStructFieldNode
- type Unmarshaler
- type Validatable
Constants ¶
const ( SchemeEmpty = "" SchemeFile = "file" // file://./config.yml SchemeEnviron = "env" // env://prefix )
Variables ¶
var ( // FromSchemes represents schemes supported for sources. FromSchemes = []string{ SchemeFile, SchemeEnviron, } // ToSchemes represents schemes supported for destrinations. ToSchemes = []string{ SchemeFile, } )
Functions ¶
func Postprocess ¶
func Postprocess(c Config, options ...PostprocessOption) error
func TreePathString ¶
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container represents configuration loaded by `Load`.
func Load ¶
func Load(v Config, options ...SourceOption) (*Container, error)
Load applies each `options` in order to fill the configuration in `v` and constructs a `*Revip` data-structure.
func (*Container) DeepClone ¶
DeepClone returns a deep copy of the configuration with the same type.
func (*Container) Default ¶
Default postprocess configuration with default values or returns an error.
func (*Container) Empty ¶
func (r *Container) Empty()
Empty allocates a new empty configuration, discarding any previously loaded data.
func (*Container) EmptyClone ¶
EmptyClone returns empty configuration type clone.
func (*Container) Path ¶
Path uses dot notation to retrieve substruct addressable by `path` or return an error if key was not found(`ErrNotFound`) or something gone terribly wrong.
type Defaultable ¶
type Defaultable interface {
Default()
}
Defaultable is an interface which any `Config` could implement to define a custom default values for sub-tree it owns.
type DestinationOption ¶
func ToFile ¶
func ToFile(path string, f Marshaler) DestinationOption
ToFile is an `DestinationOption` constructor which creates a thunk to write configuration to file addressable by `path` with content encoded with `f` marshaler.
type ErrFileNotFound ¶
ErrFileNotFound should be returned if configuration file was not found.
func (*ErrFileNotFound) Error ¶
func (e *ErrFileNotFound) Error() string
type ErrMarshal ¶
ErrMarshal should be returned if key marshaling failed.
func (*ErrMarshal) Error ¶
func (e *ErrMarshal) Error() string
type ErrPathNotFound ¶
type ErrPathNotFound struct {
Path string
}
ErrPathNotFound should be returned if key (path) was not found in configuration.
func (*ErrPathNotFound) Error ¶
func (e *ErrPathNotFound) Error() string
type ErrPostprocess ¶
ErrPostprocess represents an error occured at the postprocess stage (set defaults, validation, etc)
func (*ErrPostprocess) Error ¶
func (e *ErrPostprocess) Error() string
type ErrUnexpectedKind ¶
ErrUnexpectedKind represents an unexpected interface{} value kind received by some function. For example passing non pointer value to a function which expects pointer (like json.Unmarshal)
func (*ErrUnexpectedKind) Error ¶
func (e *ErrUnexpectedKind) Error() string
type ErrUnexpectedScheme ¶
ErrUnexpectedScheme represents an unexpected URL scheme.
func (*ErrUnexpectedScheme) Error ¶
func (e *ErrUnexpectedScheme) Error() string
type ErrUnmarshal ¶
ErrUnmarshal should be returned if key unmarshaling failed.
func (*ErrUnmarshal) Error ¶
func (e *ErrUnmarshal) Error() string
type Expandable ¶
type Expandable interface {
Expand() error
}
Expandable is an interface which any `Config` could implement to define an expansion rules for sub-tree it owns.
type Marshaler ¶
Marshaler describes a generic marshal interface for data encoding which could be used to extend supported formats by defining new `Option` implementations.
type PostprocessOption ¶
func WithDefaults ¶
func WithDefaults() PostprocessOption
func WithExpansion ¶
func WithExpansion() PostprocessOption
func WithNoNilPointers ¶
func WithNoNilPointers() PostprocessOption
func WithValidation ¶
func WithValidation() PostprocessOption
type SourceOption ¶
func FromEnviron ¶
func FromEnviron(prefix string) SourceOption
FromEnviron is an `SourceOption` constructor which creates a thunk to read configuration from environment. It uses `github.com/kelseyhightower/envconfig` underneath.
func FromFile ¶
func FromFile(path string, f Unmarshaler) SourceOption
FromFile is an `SourceOption` constructor which creates a thunk to read configuration from file addressable by `path` with content decoded with `f` unmarshaler.
func FromReader ¶
func FromReader(r io.Reader, f Unmarshaler) SourceOption
FromReader is an `SourceOption` constructor which creates a thunk to read configuration from `r` and decode it with `f` unmarshaler. Current implementation buffers all data in memory.
func FromURL ¶
func FromURL(u string, d Unmarshaler) (SourceOption, error)
FromURL creates a source from URL. Example URL's:
- file://./config.yml
- env://prefix
type Tree ¶
type Tree interface { Interface() interface{} Value() reflect.Value WithValue(reflect.Value) Tree Next() []Tree WithNext(Tree) Tree Previous() Tree WithPrevious(Tree) Tree Name() string }
func TreePathSlice ¶
type TreeArrayFieldNode ¶
func (*TreeArrayFieldNode) Name ¶
func (n *TreeArrayFieldNode) Name() string
type TreeMapFieldNode ¶
func (*TreeMapFieldNode) Name ¶
func (n *TreeMapFieldNode) Name() string
type TreeNode ¶
func (*TreeNode) WithPrevious ¶
type TreeSliceFieldNode ¶
func (*TreeSliceFieldNode) Name ¶
func (n *TreeSliceFieldNode) Name() string
type TreeStructFieldNode ¶
type TreeStructFieldNode struct { Tree Field reflect.StructField }
func (*TreeStructFieldNode) Name ¶
func (n *TreeStructFieldNode) Name() string
type Unmarshaler ¶
Unmarshaler describes a generic unmarshal interface for data decoding which could be used to extend supported formats by defining new `SourceOption` implementations.
var ( JsonUnmarshaler Unmarshaler = json.Unmarshal YamlUnmarshaler Unmarshaler = yaml.Unmarshal TomlUnmarshaler Unmarshaler = toml.Unmarshal )
type Validatable ¶
type Validatable interface {
Validate() error
}
Validatable is an interface which any `Config` could implement to define a validation rules for sub-tree it owns.