Back to godoc.org

Package config

v0.1.3
Latest Go to latest

The highest tagged major version is .

Published: Nov 3, 2017 | License: MPL-2.0 | Module: github.com/Tonsofattraction/pandora

Overview

Package config provides advanced framework to decode and validate configuration structs.

Index

Constants

const TagName = "config"

Variables

var InvalidIPError = stderrors.New("string is not valid IP")
var InvalidURLError = errors.New("string is not valid URL")

func AddKindHook

func AddKindHook(hook KindHook) (_ struct{})

func AddTypeHook

func AddTypeHook(hook TypeHook) (_ struct{})

Returning value allow do `var _ = AddHookType(xxx)`

func DebugHook

func DebugHook(f reflect.Type, t reflect.Type, data interface{}) (p interface{}, err error)

DebugHook used to debug config decode.

func Decode

func Decode(conf interface{}, result interface{}) error

Decodes conf to result. Doesn't zero fields.

func DecodeAndValidate

func DecodeAndValidate(conf interface{}, result interface{}) error

func EndpointStringValidation

func EndpointStringValidation(value string) bool

"host:port" or ":port"

func Map

func Map(dst, src interface{})

Map maps with overwrite fields from src to dst. if src filed have `map:""` tag, tag value will be used as dst field destination. src field destinations should be subset of dst fields. dst should be struct pointer. src should be struct or struct pointer. Example: you need to configure only some subset fields of struct Multi, in such case you can from this subset of fields struct Single, decode config into it, and map it on Multi.

func MaxSizeValidation

func MaxSizeValidation(v *validator.Validate, topStruct reflect.Value, currentStruct reflect.Value, field reflect.Value, fieldtype reflect.Type, fieldKind reflect.Kind, param string) bool

func MaxTimeValidation

func MaxTimeValidation(v *validator.Validate, topStruct reflect.Value, currentStruct reflect.Value, field reflect.Value, fieldtype reflect.Type, fieldKind reflect.Kind, param string) bool

func MinSizeValidation

func MinSizeValidation(v *validator.Validate, topStruct reflect.Value, currentStruct reflect.Value, field reflect.Value, fieldtype reflect.Type, fieldKind reflect.Kind, param string) bool

func MinTimeValidation

func MinTimeValidation(v *validator.Validate, topStruct reflect.Value, currentStruct reflect.Value, field reflect.Value, fieldtype reflect.Type, fieldKind reflect.Kind, param string) bool

func StringToAbstractValidation

func StringToAbstractValidation(sv StringValidation) validator.Func

StringToAbstractValidation wraps StringValidation into validator.Func.

func StringToDataSizeHook

func StringToDataSizeHook(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error)

StringToDataSizeHook converts string to datasize.Single

func StringToIPHook

func StringToIPHook(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error)

StringToIPHook converts string to net.IP

func StringToURLHook

func StringToURLHook(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error)

StringToURLHook converts string to url.URL or *url.URL

func URLPathStringValidation

func URLPathStringValidation(value string) bool

func Validate

func Validate(value interface{}) error

type StringValidation

type StringValidation func(value string) bool

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier