goar_validations

package
v0.0.0-...-711f10a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2017 License: GPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 Email

type Email struct {
	Key string
	Match
}

func ValidEmail

func ValidEmail() Email

func (Email) DefaultMessage

func (e Email) DefaultMessage() string

func (Email) GetKey

func (v Email) GetKey() string

type Length

type Length struct {
	Key string
	N   int
}

Requires an array or string to be exactly a given length.

func ValidLength

func ValidLength(n int) Length

func (Length) DefaultMessage

func (s Length) DefaultMessage() string

func (Length) GetKey

func (v Length) GetKey() string

func (Length) IsSatisfied

func (s Length) IsSatisfied(obj interface{}) bool

type Match

type Match struct {
	Key    string
	Regexp *regexp.Regexp
}

Requires a string to match a given regex.

func ValidMatch

func ValidMatch(regex *regexp.Regexp) Match

func (Match) DefaultMessage

func (m Match) DefaultMessage() string

func (Match) GetKey

func (v Match) GetKey() string

func (Match) IsSatisfied

func (m Match) IsSatisfied(obj interface{}) bool

type Max

type Max struct {
	Key string
	Max int
}

func ValidMax

func ValidMax(max int) Max

func (Max) DefaultMessage

func (m Max) DefaultMessage() string

func (Max) GetKey

func (v Max) GetKey() string

func (Max) IsSatisfied

func (m Max) IsSatisfied(obj interface{}) bool

type MaxSize

type MaxSize struct {
	Key string
	Max int
}

Requires an array or string to be at most a given length.

func ValidMaxSize

func ValidMaxSize(max int) MaxSize

func (MaxSize) DefaultMessage

func (m MaxSize) DefaultMessage() string

func (MaxSize) GetKey

func (v MaxSize) GetKey() string

func (MaxSize) IsSatisfied

func (m MaxSize) IsSatisfied(obj interface{}) bool

type Min

type Min struct {
	Key string
	Min int
}

func ValidMin

func ValidMin(min int) Min

func (Min) DefaultMessage

func (m Min) DefaultMessage() string

func (Min) GetKey

func (v Min) GetKey() string

func (Min) IsSatisfied

func (m Min) IsSatisfied(obj interface{}) bool

type MinSize

type MinSize struct {
	Key string
	Min int
}

Requires an array or string to be at least a given length.

func ValidMinSize

func ValidMinSize(min int) MinSize

func (MinSize) DefaultMessage

func (m MinSize) DefaultMessage() string

func (MinSize) GetKey

func (v MinSize) GetKey() string

func (MinSize) IsSatisfied

func (m MinSize) IsSatisfied(obj interface{}) bool

type Range

type Range struct {
	Key string
	Min
	Max
}

Requires an integer to be within Min, Max inclusive.

func ValidRange

func ValidRange(min, max int) Range

func (Range) DefaultMessage

func (r Range) DefaultMessage() string

func (Range) GetKey

func (v Range) GetKey() string

func (Range) IsSatisfied

func (r Range) IsSatisfied(obj interface{}) bool

type Required

type Required struct {
	Key string
}

func ValidRequired

func ValidRequired() Required

func (Required) DefaultMessage

func (r Required) DefaultMessage() string

func (Required) GetKey

func (v Required) GetKey() string

func (Required) IsSatisfied

func (r Required) IsSatisfied(obj interface{}) bool

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) Clear

func (v *Validation) Clear()

Clear *all* ValidationErrors

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

type Validator

type Validator interface {
	IsSatisfied(interface{}) bool
	DefaultMessage() string
	GetKey() string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL