Documentation ¶
Index ¶
- Variables
- type Email
- type Length
- type Match
- type Max
- type MaxSize
- type Min
- type MinSize
- type Range
- type Required
- type Validation
- func (v *Validation) Check(obj interface{}, checks ...Validator) *ValidationResult
- func (v *Validation) Clear()
- func (v *Validation) Email(key string, str string) *ValidationResult
- func (v *Validation) Error(key string, message string, args ...interface{}) *ValidationResult
- func (v *Validation) ErrorMap() map[string]*ValidationError
- func (v *Validation) HasErrors() bool
- func (v *Validation) Keep()
- func (v *Validation) Length(key string, obj interface{}, n int) *ValidationResult
- func (v *Validation) Match(key string, str string, regex *regexp.Regexp) *ValidationResult
- func (v *Validation) Max(key string, n int, max int) *ValidationResult
- func (v *Validation) MaxSize(key string, obj interface{}, max int) *ValidationResult
- func (v *Validation) Min(key string, n int, min int) *ValidationResult
- func (v *Validation) MinSize(key string, obj interface{}, min int) *ValidationResult
- func (v *Validation) NumErrors() int
- func (v *Validation) Range(key string, n, min, max int) *ValidationResult
- func (v *Validation) Required(key string, obj interface{}) *ValidationResult
- type ValidationError
- type ValidationResult
- type Validator
Constants ¶
This section is empty.
Variables ¶
var DefaultValidationKeys map[string]map[int]string
Register default validation keys for all calls to Controller.Validation.Func(). Map from (package).func => (line => name of first arg to Validation func) E.g. "myapp/controllers.helper" or "myapp/controllers.(*Application).Action" This is set on initialization in the generated main.go file.
Functions ¶
This section is empty.
Types ¶
type Length ¶
Requires an array or string to be exactly a given length.
func ValidLength ¶
func (Length) DefaultMessage ¶
func (Length) IsSatisfied ¶
type Match ¶
Requires a string to match a given regex.
func ValidMatch ¶
func (Match) DefaultMessage ¶
func (Match) IsSatisfied ¶
type MaxSize ¶
Requires an array or string to be at most a given length.
func ValidMaxSize ¶
func (MaxSize) DefaultMessage ¶
func (MaxSize) IsSatisfied ¶
type MinSize ¶
Requires an array or string to be at least a given length.
func ValidMinSize ¶
func (MinSize) DefaultMessage ¶
func (MinSize) IsSatisfied ¶
type Range ¶
Requires an integer to be within Min, Max inclusive.
func ValidRange ¶
func (Range) DefaultMessage ¶
func (Range) IsSatisfied ¶
type Required ¶
type Required struct {
Key string
}
func ValidRequired ¶
func ValidRequired() Required
func (Required) DefaultMessage ¶
func (Required) IsSatisfied ¶
type Validation ¶
type Validation struct { Errors []*ValidationError `gorethink:"-" json:"-"` // contains filtered or unexported fields }
A Validation context manages data validation and error messages.
func (*Validation) Check ¶
func (v *Validation) Check(obj interface{}, checks ...Validator) *ValidationResult
Apply a group of validators to a field, in order, and return the ValidationResult from the first one that fails, or the last one that succeeds.
func (*Validation) Email ¶
func (v *Validation) Email(key string, str string) *ValidationResult
func (*Validation) Error ¶
func (v *Validation) Error(key string, message string, args ...interface{}) *ValidationResult
Error adds an error to the validation context.
func (*Validation) ErrorMap ¶
func (v *Validation) ErrorMap() map[string]*ValidationError
ErrorMap returns the errors mapped by key. If there are multiple validation errors associated with a single key, the first one "wins". (Typically the first validation will be the more basic).
func (*Validation) HasErrors ¶
func (v *Validation) HasErrors() bool
HasErrors returns true if there are any (ie > 0) errors. False otherwise.
func (*Validation) Keep ¶
func (v *Validation) Keep()
Keep tells revel to set a flash cookie on the client to make the validation errors available for the next request. This is helpful when redirecting the client after the validation failed. It is good practice to always redirect upon a HTTP POST request. Thus one should use this method when HTTP POST validation failed and redirect the user back to the form.
func (*Validation) Length ¶
func (v *Validation) Length(key string, obj interface{}, n int) *ValidationResult
func (*Validation) Match ¶
func (v *Validation) Match(key string, str string, regex *regexp.Regexp) *ValidationResult
func (*Validation) Max ¶
func (v *Validation) Max(key string, n int, max int) *ValidationResult
func (*Validation) MaxSize ¶
func (v *Validation) MaxSize(key string, obj interface{}, max int) *ValidationResult
func (*Validation) Min ¶
func (v *Validation) Min(key string, n int, min int) *ValidationResult
func (*Validation) MinSize ¶
func (v *Validation) MinSize(key string, obj interface{}, min int) *ValidationResult
func (*Validation) NumErrors ¶
func (v *Validation) NumErrors() int
NumErrors returns the number of validation errors for a given instance
func (*Validation) Range ¶
func (v *Validation) Range(key string, n, min, max int) *ValidationResult
func (*Validation) Required ¶
func (v *Validation) Required(key string, obj interface{}) *ValidationResult
Required tests that the argument is non-nil and non-empty (if string or list)
type ValidationError ¶
type ValidationError struct {
Message, Key string
}
Simple struct to store the Message & Key of a validation error
func (*ValidationError) String ¶
func (e *ValidationError) String() string
String returns the Message field of the ValidationError struct.
type ValidationResult ¶
type ValidationResult struct { Error *ValidationError Ok bool }
A ValidationResult is returned from every validation method. It provides an indication of success, and a pointer to the Error (if any).
func (*ValidationResult) Message ¶
func (r *ValidationResult) Message(message string, args ...interface{}) *ValidationResult
Message sets the error message for a ValidationResult. Returns itself to allow chaining. Allows Sprintf() type calling with multiple parameters