Documentation ¶
Overview ¶
Package config provides advanced framework to decode and validate configuration structs.
Index ¶
- Constants
- Variables
- func AddKindHook(hook KindHook) (_ struct{})
- func AddTypeHook(hook TypeHook) (_ struct{})
- func DebugHook(f reflect.Type, t reflect.Type, data interface{}) (p interface{}, err error)
- func Decode(conf interface{}, result interface{}) error
- func DecodeAndValidate(conf interface{}, result interface{}) error
- func EndpointStringValidation(value string) bool
- func Map(dst, src interface{})
- func MaxSizeValidation(v *validator.Validate, topStruct reflect.Value, currentStruct reflect.Value, ...) bool
- func MaxTimeValidation(v *validator.Validate, topStruct reflect.Value, currentStruct reflect.Value, ...) bool
- func MinSizeValidation(v *validator.Validate, topStruct reflect.Value, currentStruct reflect.Value, ...) bool
- func MinTimeValidation(v *validator.Validate, topStruct reflect.Value, currentStruct reflect.Value, ...) bool
- func StringToAbstractValidation(sv StringValidation) validator.Func
- func StringToDataSizeHook(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error)
- func StringToIPHook(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error)
- func StringToURLHook(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error)
- func URLPathStringValidation(value string) bool
- func Validate(value interface{}) error
- type KindHook
- type StringValidation
- type TypeHook
Constants ¶
const TagName = "config"
Variables ¶
var InvalidIPError = stderrors.New("string is not valid IP")
var InvalidURLError = errors.New("string is not valid URL")
Functions ¶
func AddKindHook ¶
func AddKindHook(hook KindHook) (_ struct{})
func AddTypeHook ¶
func AddTypeHook(hook TypeHook) (_ struct{})
Returning value allow do `var _ = AddHookType(xxx)`
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 ¶
"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 MaxTimeValidation ¶
func MinSizeValidation ¶
func MinTimeValidation ¶
func StringToAbstractValidation ¶
func StringToAbstractValidation(sv StringValidation) validator.Func
StringToAbstractValidation wraps StringValidation into validator.Func.
func StringToDataSizeHook ¶
StringToDataSizeHook converts string to datasize.Single
func StringToIPHook ¶
StringToIPHook converts string to net.IP
func StringToURLHook ¶
StringToURLHook converts string to url.URL or *url.URL
func URLPathStringValidation ¶
Types ¶
type KindHook ¶
type KindHook mapstructure.DecodeHookFuncKind
type StringValidation ¶
type TypeHook ¶
type TypeHook mapstructure.DecodeHookFuncType