Documentation ¶
Index ¶
- Constants
- Variables
- type Domain
- type Email
- type FilePath
- type IPAddr
- type Length
- type MacAddr
- type Match
- type Max
- type MaxSize
- type Min
- type MinSize
- type PureText
- type Range
- type Required
- type URL
- type Validation
- func (v *Validation) Check(obj interface{}, checks ...Validator) *ValidationResult
- func (v *Validation) Clear()
- func (v *Validation) Domain(str string) *ValidationResult
- func (v *Validation) Email(str string) *ValidationResult
- func (v *Validation) Error(message string, args ...interface{}) *ValidationResult
- func (v *Validation) ErrorKey(message string, args ...interface{}) *ValidationResult
- func (v *Validation) ErrorMap() map[string]*ValidationError
- func (v *Validation) FilePath(str string, m int) *ValidationResult
- func (v *Validation) HasErrors() bool
- func (v *Validation) IPAddr(str string, cktype ...int) *ValidationResult
- func (v *Validation) Keep()
- func (v *Validation) Length(obj interface{}, n int) *ValidationResult
- func (v *Validation) MacAddr(str string) *ValidationResult
- func (v *Validation) Match(str string, regex *regexp.Regexp) *ValidationResult
- func (v *Validation) Max(n int, max int) *ValidationResult
- func (v *Validation) MaxFloat(n float64, max float64) *ValidationResult
- func (v *Validation) MaxSize(obj interface{}, max int) *ValidationResult
- func (v *Validation) Min(n int, min int) *ValidationResult
- func (v *Validation) MinFloat(n float64, min float64) *ValidationResult
- func (v *Validation) MinSize(obj interface{}, min int) *ValidationResult
- func (v *Validation) PureText(str string, m int) *ValidationResult
- func (v *Validation) Range(n, min, max int) *ValidationResult
- func (v *Validation) RangeFloat(n, min, max float64) *ValidationResult
- func (v *Validation) Required(obj interface{}) *ValidationResult
- func (v *Validation) URL(str string) *ValidationResult
- func (v *Validation) ValidationResult(ok bool) *ValidationResult
- type ValidationError
- type ValidationResult
- type Validator
Constants ¶
const ( None = 0 IPAny = 1 IPv4 = 32 // IPv4 (32 chars) IPv6 = 39 // IPv6(39 chars) IPv4MappedIPv6 = 45 // IP4-mapped IPv6 (45 chars) , Ex) ::FFFF:129.144.52.38 IPv4CIDR = IPv4 + 3 IPv6CIDR = IPv6 + 3 IPv4MappedIPv6CIDR = IPv4MappedIPv6 + 3 )
const ( NORMAL = 0 STRICT = 4 )
NORMAL BenchmarkRegex-8 2000000000 0.24 ns/op STRICT BenchmarkLoop-8 2000000000 0.01 ns/op
const ( ONLY_FILENAME = 0 ALLOW_RELATIVE_PATH = 1 )
Variables ¶
var DefaultValidationKeys map[string]map[int]string
DefaultValidationKeys 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 Domain ¶
Requires a Domain string to be exactly
func ValidDomain ¶
func ValidDomain() Domain
func (Domain) DefaultMessage ¶
func (Domain) IsSatisfied ¶
type Email ¶
type Email struct {
Match
}
func ValidEmail ¶
func ValidEmail() Email
func (Email) DefaultMessage ¶
type FilePath ¶
type FilePath struct {
Mode int
}
Requires an string to be sanitary file path
func ValidFilePath ¶
func (FilePath) DefaultMessage ¶
func (FilePath) IsSatisfied ¶
type IPAddr ¶
type IPAddr struct {
Vaildtypes []int
}
Requires a string(IP Address) to be within IP Pattern type inclusive.
func ValidIPAddr ¶
Requires an IP Address string to be exactly a given validation type (IPv4, IPv6, IPv4MappedIPv6, IPv4CIDR, IPv6CIDR, IPv4MappedIPv6CIDR OR IPAny)
func (IPAddr) DefaultMessage ¶
func (IPAddr) IsSatisfied ¶
type Length ¶
type Length struct {
N int
}
Length requires an array or string to be exactly a given length.
func ValidLength ¶
func (Length) DefaultMessage ¶
func (Length) IsSatisfied ¶
type MacAddr ¶
type MacAddr struct{}
Requires a MAC Address string to be exactly
func ValidMacAddr ¶
func ValidMacAddr() MacAddr
func (MacAddr) DefaultMessage ¶
func (MacAddr) IsSatisfied ¶
type Match ¶
Match requires a string to match a given regex.
func ValidMatch ¶
func (Match) DefaultMessage ¶
func (Match) IsSatisfied ¶
type Max ¶
type Max struct {
Max float64
}
func ValidMaxFloat ¶
func (Max) DefaultMessage ¶
func (Max) IsSatisfied ¶
type MaxSize ¶
type MaxSize struct {
Max int
}
MaxSize requires an array or string to be at most a given length.
func ValidMaxSize ¶
func (MaxSize) DefaultMessage ¶
func (MaxSize) IsSatisfied ¶
type Min ¶
type Min struct {
Min float64
}
func ValidMinFloat ¶
func (Min) DefaultMessage ¶
func (Min) IsSatisfied ¶
type MinSize ¶
type MinSize struct {
Min int
}
MinSize requires an array or string to be at least a given length.
func ValidMinSize ¶
func (MinSize) DefaultMessage ¶
func (MinSize) IsSatisfied ¶
type PureText ¶
type PureText struct {
Mode int
}
Requires a string to be without invisible characters
func ValidPureText ¶
func (PureText) DefaultMessage ¶
func (PureText) IsSatisfied ¶
type Range ¶
Range requires an integer to be within Min, Max inclusive.
func ValidRange ¶
func ValidRangeFloat ¶
func (Range) DefaultMessage ¶
func (Range) IsSatisfied ¶
type Required ¶
type Required struct{}
func ValidRequired ¶
func ValidRequired() Required
func (Required) DefaultMessage ¶
func (Required) IsSatisfied ¶
type Validation ¶
type Validation struct { Errors []*ValidationError Request *http.Request Translator func(locale, message string, args ...interface{}) string // contains filtered or unexported fields }
Validation context manages data validation and error messages.
func (*Validation) Check ¶
func (v *Validation) Check(obj interface{}, checks ...Validator) *ValidationResult
Check applies 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) Domain ¶
func (v *Validation) Domain(str string) *ValidationResult
func (*Validation) Email ¶
func (v *Validation) Email(str string) *ValidationResult
func (*Validation) Error ¶
func (v *Validation) Error(message string, args ...interface{}) *ValidationResult
Error adds an error to the validation context.
func (*Validation) ErrorKey ¶
func (v *Validation) ErrorKey(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) FilePath ¶
func (v *Validation) FilePath(str string, m int) *ValidationResult
func (*Validation) HasErrors ¶
func (v *Validation) HasErrors() bool
HasErrors returns true if there are any (ie > 0) errors. False otherwise.
func (*Validation) IPAddr ¶
func (v *Validation) IPAddr(str string, cktype ...int) *ValidationResult
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(obj interface{}, n int) *ValidationResult
func (*Validation) MacAddr ¶
func (v *Validation) MacAddr(str string) *ValidationResult
func (*Validation) Match ¶
func (v *Validation) Match(str string, regex *regexp.Regexp) *ValidationResult
func (*Validation) Max ¶
func (v *Validation) Max(n int, max int) *ValidationResult
func (*Validation) MaxFloat ¶
func (v *Validation) MaxFloat(n float64, max float64) *ValidationResult
func (*Validation) MaxSize ¶
func (v *Validation) MaxSize(obj interface{}, max int) *ValidationResult
func (*Validation) Min ¶
func (v *Validation) Min(n int, min int) *ValidationResult
func (*Validation) MinFloat ¶
func (v *Validation) MinFloat(n float64, min float64) *ValidationResult
func (*Validation) MinSize ¶
func (v *Validation) MinSize(obj interface{}, min int) *ValidationResult
func (*Validation) PureText ¶
func (v *Validation) PureText(str string, m int) *ValidationResult
func (*Validation) Range ¶
func (v *Validation) Range(n, min, max int) *ValidationResult
func (*Validation) RangeFloat ¶
func (v *Validation) RangeFloat(n, min, max float64) *ValidationResult
func (*Validation) Required ¶
func (v *Validation) Required(obj interface{}) *ValidationResult
Required tests that the argument is non-nil and non-empty (if string or list)
func (*Validation) URL ¶
func (v *Validation) URL(str string) *ValidationResult
func (*Validation) ValidationResult ¶
func (v *Validation) ValidationResult(ok bool) *ValidationResult
Error adds an error to the validation context.
type ValidationError ¶
type ValidationError struct {
Message, Key string
}
ValidationError 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 Locale string Translator func(locale, message string, args ...interface{}) string }
ValidationResult is returned from every validation method. It provides an indication of success, and a pointer to the Error (if any).
func (*ValidationResult) Key ¶
func (r *ValidationResult) Key(key string) *ValidationResult
Key sets the ValidationResult's Error "key" and returns itself for chaining
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
func (*ValidationResult) MessageKey ¶
func (r *ValidationResult) MessageKey(message string, args ...interface{}) *ValidationResult
Allow a message key to be passed into the validation result. The Validation has already setup the translator to translate the message key