config

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2017 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const TagName = "config"

Variables

View Source
var InvalidIPError = stderrors.New("string is not valid IP")
View Source
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 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

Types

type StringValidation

type StringValidation func(value string) bool

Jump to

Keyboard shortcuts

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