Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
func Add(tag string, method ValidatorFunc) (err error)
Add a new validation method for a given struct tag. If a validation method already exists this will return an error
Types ¶
type ErrInvalid ¶
type ErrInvalid struct {
ValidationData
Failure string
Message string
}
func (ErrInvalid) Error ¶
func (t ErrInvalid) Error() string
type ErrNoValidationMethod ¶
type ErrNoValidationMethod struct {
Tag string
}
func (ErrNoValidationMethod) Error ¶
func (t ErrNoValidationMethod) Error() string
type ValidationData ¶
type ValidationData struct {
// The name of the field being validated
Field string
// The override message for validation failure
Message string
// The value of the struct field being validated
Value interface{}
// Arguments from the validation tags. For example, in the following
// definition Args will will contain a single "5":
//
// struct {
// Age `validate:"GreaterThan:5"`
// }
//
// Unfortunately, due to the nature of tags these will always be strings.
Args []string
}
type ValidatorFunc ¶
type ValidatorFunc func(ValidationData) error
All validation methods must return an ErrInvalid error type if the data is invalid, or nil if the data is valid
func Get ¶
func Get(tag string) (method ValidatorFunc, err error)
Return a registered validation method for a given tag