Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultValueObscurator(limit int, str string) string
- func GetErrorMessageByKey(options ValidatorOptions, key int, value interface{}) string
- func ObscurateLeft(numChars int, str string) string
- func ObscurateRight(numChars int, str string) string
- type FloatValidatorOptions
- type IntValidatorOptions
- type LengthValidatorOptions
- type MessageFunc
- type MessageFuncs
- type NotEmptyValidatorOptions
- type RegexValidatorOptions
- type Validator
- func DigitValidator(options RegexValidatorOptions) Validator
- func DigitValidator1() Validator
- func FloatRangeValidator(options ValidatorOptions) Validator
- func IntRangeValidator(options ValidatorOptions) Validator
- func LengthValidator(options LengthValidatorOptions) Validator
- func NotEmptyValidator(options ValidatorOptions) Validator
- func NotEmptyValidator1() Validator
- func RegexValidator(options RegexValidatorOptions) Validator
- type ValidatorGenerator
- type ValidatorOptions
- type ValueObscurator
Constants ¶
const ( DoesNotMatchPattern = iota EmptyNotAllowed NotAValidType NotWithinRange )
const (
DefaultEmptyNotAllowedMsg = "Empty values are not allowed."
)
Variables ¶
var DefaultInRangeMessageFuncs = MessageFuncs{ NotAValidType: func(options ValidatorOptions, x interface{}) string { return fmt.Sprintf("%v is not a validatable numeric type.", x) }, }
Functions ¶
func DefaultValueObscurator ¶
DefaultValueObscurator Returns an obscured string representation of given value. Obscures string using "*" character up to given `limit`.
func GetErrorMessageByKey ¶
func GetErrorMessageByKey(options ValidatorOptions, key int, value interface{}) string
GetErrorMessageByKey is a generic function that gets the message function from a collection of message template functions and calls it using passed in options and value values.
func ObscurateLeft ¶
func ObscurateRight ¶
Types ¶
type FloatValidatorOptions ¶
type FloatValidatorOptions struct { MessageFuncs *MessageFuncs Min float64 Max float64 Inclusive bool }
func NewFloatRangeValidatorOptions ¶
func NewFloatRangeValidatorOptions() FloatValidatorOptions
func (FloatValidatorOptions) GetErrorMessageByKey ¶
func (n FloatValidatorOptions) GetErrorMessageByKey(key int, x interface{}) string
func (FloatValidatorOptions) GetMessageFuncs ¶
func (n FloatValidatorOptions) GetMessageFuncs() *MessageFuncs
func (FloatValidatorOptions) GetValueObscurator ¶
func (n FloatValidatorOptions) GetValueObscurator() ValueObscurator
type IntValidatorOptions ¶
type IntValidatorOptions struct { MessageFuncs *MessageFuncs Min int64 Max int64 Inclusive bool }
func NewIntRangeValidatorOptions ¶
func NewIntRangeValidatorOptions() IntValidatorOptions
func (IntValidatorOptions) GetErrorMessageByKey ¶
func (n IntValidatorOptions) GetErrorMessageByKey(key int, x interface{}) string
func (IntValidatorOptions) GetMessageFuncs ¶
func (n IntValidatorOptions) GetMessageFuncs() *MessageFuncs
func (IntValidatorOptions) GetValueObscurator ¶
func (n IntValidatorOptions) GetValueObscurator() ValueObscurator
type LengthValidatorOptions ¶
type LengthValidatorOptions struct { MessageFuncs *MessageFuncs Min int64 Max int64 Inclusive bool }
func NewLengthValidatorOptions ¶
func NewLengthValidatorOptions() LengthValidatorOptions
func (LengthValidatorOptions) GetErrorMessageByKey ¶
func (n LengthValidatorOptions) GetErrorMessageByKey(key int, x interface{}) string
func (LengthValidatorOptions) GetMessageFuncs ¶
func (n LengthValidatorOptions) GetMessageFuncs() *MessageFuncs
func (LengthValidatorOptions) GetValueObscurator ¶
func (n LengthValidatorOptions) GetValueObscurator() ValueObscurator
type MessageFunc ¶
type MessageFunc func(options ValidatorOptions, x interface{}) string // returns message
type MessageFuncs ¶
type MessageFuncs map[int]MessageFunc // message templates
var DefaultLengthValidatorMessageFuncs MessageFuncs
var (
DigitValidatorMessageFuncs MessageFuncs
)
var RegexValidatorMessageFuncs *MessageFuncs
type NotEmptyValidatorOptions ¶
type NotEmptyValidatorOptions struct {
MessageFuncs *MessageFuncs
}
func NewNotEmptyValidatorOptions ¶
func NewNotEmptyValidatorOptions() NotEmptyValidatorOptions
func (NotEmptyValidatorOptions) GetErrorMessageByKey ¶
func (n NotEmptyValidatorOptions) GetErrorMessageByKey(key int, x interface{}) string
func (NotEmptyValidatorOptions) GetMessageFuncs ¶
func (n NotEmptyValidatorOptions) GetMessageFuncs() *MessageFuncs
func (NotEmptyValidatorOptions) GetValueObscurator ¶
func (n NotEmptyValidatorOptions) GetValueObscurator() ValueObscurator
type RegexValidatorOptions ¶
type RegexValidatorOptions struct { Pattern *regexp.Regexp MessageFuncs *MessageFuncs }
func NewRegexValidatorOptions ¶
func NewRegexValidatorOptions() RegexValidatorOptions
func (RegexValidatorOptions) GetErrorMessageByKey ¶
func (n RegexValidatorOptions) GetErrorMessageByKey(key int, x interface{}) string
func (RegexValidatorOptions) GetMessageFuncs ¶
func (n RegexValidatorOptions) GetMessageFuncs() *MessageFuncs
func (RegexValidatorOptions) GetValueObscurator ¶
func (n RegexValidatorOptions) GetValueObscurator() ValueObscurator
type Validator ¶
func DigitValidator ¶
func DigitValidator(options RegexValidatorOptions) Validator
DigitValidator - Returns `(true, nil)` for `uint`, `int`, and strings containing only digit characters (numbers). For every other value the returned validator will always return `(false, []string{})` where the second return value is the error messages returned for current run. Note: The `Pattern` property of passed in `RegexValidatorOptions` gets ignored and the internally defined one gets used.
func DigitValidator1 ¶
func DigitValidator1() Validator
DigitValidator1 - Ignores options param and just returns a validator which contains default error messages in message templates
func FloatRangeValidator ¶
func FloatRangeValidator(options ValidatorOptions) Validator
func IntRangeValidator ¶
func IntRangeValidator(options ValidatorOptions) Validator
func LengthValidator ¶
func LengthValidator(options LengthValidatorOptions) Validator
func NotEmptyValidator ¶
func NotEmptyValidator(options ValidatorOptions) Validator
func NotEmptyValidator1 ¶
func NotEmptyValidator1() Validator
func RegexValidator ¶
func RegexValidator(options RegexValidatorOptions) Validator
type ValidatorGenerator ¶
type ValidatorGenerator func(options ValidatorOptions) Validator
type ValidatorOptions ¶
type ValidatorOptions interface { GetMessageFuncs() *MessageFuncs GetErrorMessageByKey(key int, value interface{}) string GetValueObscurator() ValueObscurator }
type ValueObscurator ¶
For obscuring values in error messages (composed into validators
where required (for example in a credit-card validator))