Documentation
¶
Index ¶
- Variables
- type Validator
- func (v *Validator) AppendRule(rule rules.Rule) *Validator
- func (v *Validator) SetFailFast(failFast bool) *Validator
- func (v *Validator) SetFieldMessage(field, rule, message string) *Validator
- func (v *Validator) SetMessage(ruleErr, message string) *Validator
- func (v *Validator) SetMessages(messages map[string]string) *Validator
- func (v *Validator) Validate(input interface{}) (map[string][]string, error)
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidInput = errors.New("the given input needs to be of type struct")
ErrInvalidInput is returned when the input to the Validate method is not a struct.
Functions ¶
This section is empty.
Types ¶
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator struct contains custom and predefined validation rules along with error messages.
func NewValidator ¶
func NewValidator() *Validator
NewValidator constructs a new Validator with predefined rules and default messages.
func (*Validator) AppendRule ¶
AppendRule can be used to store / add a custom rule. The rule needs to implement the rules.Rule interface
func (*Validator) SetFailFast ¶ added in v2.1.0
SetFailFast will set the failFast flag. Upcoming rules will be skipped per field if we have at least one error in the list This essentially shrinks the length of error messages to a maximum of 1
func (*Validator) SetFieldMessage ¶
SetMessage does the same as SetMessage but for specific field on the struct.
func (*Validator) SetMessage ¶
SetMessage will override the default message for the given ruleErr like "no-string", etc.
func (*Validator) SetMessages ¶
SetMessages can be used for translations and replaces the map of messages with the given map