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 DefaultHooks() []mapstructure.DecodeHookFunc
- func EndpointStringValidation(value string) bool
- func GetHooks() []mapstructure.DecodeHookFunc
- func Map(dst, src interface{})
- func MaxSizeValidation(fl validator.FieldLevel) bool
- func MaxTimeValidation(fl validator.FieldLevel) bool
- func MinSizeValidation(fl validator.FieldLevel) bool
- func MinTimeValidation(fl validator.FieldLevel) bool
- func RegisterCustom(v CustomValidation, types ...interface{}) (_ struct{})
- func SetHooks(h []mapstructure.DecodeHookFunc)
- 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 TextUnmarshallerHook(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error)
- func URLPathStringValidation(value string) bool
- func Validate(value interface{}) error
- func VariableInjectHook(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error)
- type CustomValidation
- type KindHook
- type StringValidation
- type TypeHook
- type ValidateHandle
Constants ¶
const TagName = "config"
Variables ¶
var ErrInvalidIP = 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 DefaultHooks ¶ added in v0.3.0
func DefaultHooks() []mapstructure.DecodeHookFunc
func EndpointStringValidation ¶
"host:port" or ":port"
func GetHooks ¶ added in v0.3.0
func GetHooks() []mapstructure.DecodeHookFunc
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(fl validator.FieldLevel) bool
func MaxTimeValidation ¶
func MaxTimeValidation(fl validator.FieldLevel) bool
func MinSizeValidation ¶
func MinSizeValidation(fl validator.FieldLevel) bool
func MinTimeValidation ¶
func MinTimeValidation(fl validator.FieldLevel) bool
func RegisterCustom ¶ added in v0.3.0
func RegisterCustom(v CustomValidation, types ...interface{}) (_ struct{})
RegisterCustom used to set custom validation check hooks on specific types, that will be called on such type validation, even if it is nested field.
func SetHooks ¶ added in v0.3.0
func SetHooks(h []mapstructure.DecodeHookFunc)
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 TextUnmarshallerHook ¶ added in v0.3.0
func URLPathStringValidation ¶
Types ¶
type CustomValidation ¶ added in v0.3.0
type CustomValidation func(h ValidateHandle)
type KindHook ¶
type KindHook mapstructure.DecodeHookFuncKind
type StringValidation ¶
type TypeHook ¶
type TypeHook mapstructure.DecodeHookFuncType
type ValidateHandle ¶ added in v0.3.0
type ValidateHandle interface { Value() interface{} ReportError(field, reason string) }