config

package
v0.5.16 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MPL-2.0 Imports: 17 Imported by: 16

Documentation

Overview

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

Index

Constants

View Source
const TagName = "config"

Variables

View Source
var ErrInvalidIP = 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 DefaultHooks added in v0.3.0

func DefaultHooks() []mapstructure.DecodeHookFunc

func EndpointStringValidation

func EndpointStringValidation(value string) bool

"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

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 TextUnmarshallerHook added in v0.3.0

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

func URLPathStringValidation

func URLPathStringValidation(value string) bool

func Validate

func Validate(value interface{}) error

func VariableInjectHook added in v0.4.0

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

VariableInjectHook injects values into ${VAR_NAME} placeholders

Types

type CustomValidation added in v0.3.0

type CustomValidation func(h ValidateHandle)

type StringValidation

type StringValidation func(value string) bool

type ValidateHandle added in v0.3.0

type ValidateHandle interface {
	Value() interface{}
	ReportError(field, reason string)
}

Jump to

Keyboard shortcuts

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