Documentation ¶
Overview ¶
Package validator provides types and functions for validator implementations
Index ¶
- type FieldError
- type FormValidator
- func (f *FormValidator) BoolField(name string) *List
- func (f *FormValidator) DateField(name string) *List
- func (f *FormValidator) DateTimeField(name string) *List
- func (f *FormValidator) DurationField(name string) *List
- func (f *FormValidator) Eval(values url.Values) *ValidationError
- func (f *FormValidator) FloatField(name string) *List
- func (f *FormValidator) IntField(name string) *List
- func (f *FormValidator) TimeField(name string) *List
- type Func
- type List
- type Validatable
- type ValidationError
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FieldError ¶
type FieldError struct { Message string `json:"message"` Params map[string]interface{} `json:"params,omitempty"` }
FieldError represents an error in the validated object. It has a Message field which is a error message template, and Params map which would be applied to the error message.
func NewFieldError ¶
func NewFieldError(message string, params map[string]interface{}) *FieldError
NewFieldError creates a new ValidationError object.
func (*FieldError) Error ¶
func (v *FieldError) Error() string
Returns string representation of the error.
func (*FieldError) String ¶
func (v *FieldError) String() string
Returns string representation of the error
type FormValidator ¶
type FormValidator struct { *Validator // contains filtered or unexported fields }
FormValidator is a validator to validate url.Value
func NewFormValidator ¶
func NewFormValidator() *FormValidator
NewFormValidator returns a new *FormValidator
func (*FormValidator) BoolField ¶
func (f *FormValidator) BoolField(name string) *List
BoolField - a named field for the bool value.
func (*FormValidator) DateField ¶
func (f *FormValidator) DateField(name string) *List
DateField - a named field for the time.Time value (formatted as xtime.ParseDate compatible).
func (*FormValidator) DateTimeField ¶
func (f *FormValidator) DateTimeField(name string) *List
DateTimeField - a named field for the time.Time value (formatted as xtime.Parse compatible).
func (*FormValidator) DurationField ¶
func (f *FormValidator) DurationField(name string) *List
DurationField - a named field for the time.Duration value.
func (*FormValidator) Eval ¶
func (f *FormValidator) Eval(values url.Values) *ValidationError
Eval evaluates the `values` and returns the error if the validation fails.
func (*FormValidator) FloatField ¶
func (f *FormValidator) FloatField(name string) *List
FloatField - a named field for the float value.
func (*FormValidator) IntField ¶
func (f *FormValidator) IntField(name string) *List
IntField - a named field for the int value.
func (*FormValidator) TimeField ¶
func (f *FormValidator) TimeField(name string) *List
TimeField - a named field for the time.Time value (formatted as xtime.ParseTime compatible).
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is a list of Func
func (*List) Func ¶
func (l *List) Func(f func(v interface{}) *FieldError) *List
Func to run the given custom validation fucntion `f`.
type Validatable ¶
Validatable is an interface for an object to be validated
func NewValidatable ¶
func NewValidatable(i interface{}) Validatable
NewValidatable returns a Validatable for any types of struct object
type ValidationError ¶
type ValidationError struct { Errors map[string][]*FieldError `json:"errors"` Value interface{} `json:"value"` }
ValidationError is an error returned by Eval(Validator, interface{})
type Validator ¶
type Validator struct { *List // object validators // contains filtered or unexported fields }
Validator is a struct that contains validator functions
func (*Validator) Eval ¶
func (v *Validator) Eval(i interface{}) *ValidationError
Eval to evaluate the object t and return the validation result. nil would be returned on no validation errors.