Documentation ¶
Index ¶
- Constants
- Variables
- type ConstraintError
- type ConstraintInterface
- func Between(min, max interface{}) ConstraintInterface
- func Callback(validate func(value interface{}, flags types.Flag) ErrorInterface, strict bool) ConstraintInterface
- func Contains(value interface{}) ConstraintInterface
- func Equal(value interface{}) ConstraintInterface
- func Excludes(value interface{}) ConstraintInterface
- func GreaterThan(value interface{}) ConstraintInterface
- func GreaterThanOrEqual(value interface{}) ConstraintInterface
- func Identical(value interface{}) ConstraintInterface
- func Length(value uint) ConstraintInterface
- func LessThan(value interface{}) ConstraintInterface
- func LessThanOrEqual(value interface{}) ConstraintInterface
- func MaxLength(value uint) ConstraintInterface
- func MinLength(value uint) ConstraintInterface
- func NotEqual(value interface{}) ConstraintInterface
- func NotIdentical(value interface{}) ConstraintInterface
- func ParseTag(tag string) (constraints []ConstraintInterface, err error)
- func Regexp(expr string) ConstraintInterface
- func RegexpCompiled(re *regexp.Regexp) ConstraintInterface
- func RegexpPOSIX(expr string) ConstraintInterface
- type Each
- type ErrorInterface
- type Map
- type Required
- type Struct
- type TagOption
- func (o TagOption) NoValue(lambda func() ConstraintInterface) (ConstraintInterface, error)
- func (o TagOption) WithBool(lambda func(v bool) ConstraintInterface) (ConstraintInterface, error)
- func (o TagOption) WithFloat(lambda func(v float64) ConstraintInterface) (ConstraintInterface, error)
- func (o TagOption) WithInt(lambda func(v int64) ConstraintInterface) (ConstraintInterface, error)
- func (o TagOption) WithString(lambda func(v string) ConstraintInterface) (ConstraintInterface, error)
- func (o TagOption) WithTag(lambda func(v []ConstraintInterface) ConstraintInterface) (ConstraintInterface, error)
- func (o TagOption) WithUint(lambda func(v uint64) ConstraintInterface) (ConstraintInterface, error)
- func (o TagOption) WithValue(lambda func(v interface{}) ConstraintInterface) (ConstraintInterface, error)
- type Timestamp
- type Type
- type Valid
- type ValidationError
Constants ¶
View Source
const ( Empty = Required(false) NotEmpty = Required(true) )
View Source
const ( DateFormat = "2006-01-02" TimeFormat = "15:04:05" DateTimeFormat = "2006-01-02 15:04:05" )
View Source
const ( Date = Timestamp(DateFormat) Time = Timestamp(TimeFormat) DateTime = Timestamp(DateTimeFormat) )
View Source
const ( Nil = Valid(false) NotNil = Valid(true) )
View Source
const ( StrictValidation types.Flag FastValidation OmitEmpty AllowExtraFields AllowMissingFields )
Variables ¶
View Source
var ( True = Equal(true) False = Equal(false) )
View Source
var Flags = StrictValidation | OmitEmpty | AllowMissingFields
View Source
var TagName = "validate"
View Source
var TagOptions = map[string]func(o TagOption) (constraint ConstraintInterface, err error){ "required": func(o TagOption) (constraint ConstraintInterface, err error) { return o.WithBool(func(v bool) ConstraintInterface { return Required(v) }) }, "valid": func(o TagOption) (constraint ConstraintInterface, err error) { return o.WithBool(func(v bool) ConstraintInterface { return Valid(v) }) }, "type": func(o TagOption) (constraint ConstraintInterface, err error) { return o.WithString(func(v string) ConstraintInterface { return Type(v) }) }, "len": func(o TagOption) (constraint ConstraintInterface, err error) { return o.WithUint(func(v uint64) ConstraintInterface { return Length(uint(v)) }) }, "minlen": func(o TagOption) (constraint ConstraintInterface, err error) { return o.WithUint(func(v uint64) ConstraintInterface { return MinLength(uint(v)) }) }, "maxlen": func(o TagOption) (constraint ConstraintInterface, err error) { return o.WithUint(func(v uint64) ConstraintInterface { return MaxLength(uint(v)) }) }, "true": func(o TagOption) (constraint ConstraintInterface, err error) { return o.NoValue(func() ConstraintInterface { return True }) }, "false": func(o TagOption) (constraint ConstraintInterface, err error) { return o.NoValue(func() ConstraintInterface { return False }) }, "eq": func(o TagOption) (constraint ConstraintInterface, err error) { return o.WithValue(func(v interface{}) ConstraintInterface { return Equal(v) }) }, "lt": func(o TagOption) (constraint ConstraintInterface, err error) { return o.WithValue(func(v interface{}) ConstraintInterface { return LessThan(v) }) }, "lte": func(o TagOption) (constraint ConstraintInterface, err error) { return o.WithValue(func(v interface{}) ConstraintInterface { return LessThanOrEqual(v) }) }, "gt": func(o TagOption) (constraint ConstraintInterface, err error) { return o.WithValue(func(v interface{}) ConstraintInterface { return GreaterThan(v) }) }, "gte": func(o TagOption) (constraint ConstraintInterface, err error) { return o.WithValue(func(v interface{}) ConstraintInterface { return GreaterThanOrEqual(v) }) }, "re": func(o TagOption) (constraint ConstraintInterface, err error) { return o.WithString(func(v string) ConstraintInterface { return Regexp(v) }) }, "repsx": func(o TagOption) (constraint ConstraintInterface, err error) { return o.WithString(func(v string) ConstraintInterface { return RegexpPOSIX(v) }) }, "contains": func(o TagOption) (constraint ConstraintInterface, err error) { return o.WithValue(func(v interface{}) ConstraintInterface { return Contains(v) }) }, "excludes": func(o TagOption) (constraint ConstraintInterface, err error) { return o.WithValue(func(v interface{}) ConstraintInterface { return Excludes(v) }) }, "date": func(o TagOption) (constraint ConstraintInterface, err error) { return o.NoValue(func() ConstraintInterface { return Date }) }, "time": func(o TagOption) (constraint ConstraintInterface, err error) { return o.NoValue(func() ConstraintInterface { return Time }) }, "datetime": func(o TagOption) (constraint ConstraintInterface, err error) { return o.NoValue(func() ConstraintInterface { return DateTime }) }, "timestamp": func(o TagOption) (constraint ConstraintInterface, err error) { return o.WithString(func(v string) ConstraintInterface { return Timestamp(v) }) }, }
Functions ¶
This section is empty.
Types ¶
type ConstraintError ¶
type ConstraintError struct { Constraint ConstraintInterface VarName string Message string Args []interface{} }
func NewConstraintError ¶
func NewConstraintError(constraint ConstraintInterface, message string, args ...interface{}) *ConstraintError
func UnexpectedTypeError ¶
func UnexpectedTypeError(constraint ConstraintInterface, value interface{}) *ConstraintError
func (*ConstraintError) Error ¶
func (e *ConstraintError) Error() string
func (*ConstraintError) Errors ¶
func (e *ConstraintError) Errors() ValidationError
type ConstraintInterface ¶
type ConstraintInterface interface { Validate(value interface{}, flags types.Flag) ErrorInterface Strict() bool Name() string }
func Between ¶
func Between(min, max interface{}) ConstraintInterface
func Callback ¶
func Callback(validate func(value interface{}, flags types.Flag) ErrorInterface, strict bool) ConstraintInterface
func Contains ¶
func Contains(value interface{}) ConstraintInterface
func Equal ¶
func Equal(value interface{}) ConstraintInterface
func Excludes ¶
func Excludes(value interface{}) ConstraintInterface
func GreaterThan ¶
func GreaterThan(value interface{}) ConstraintInterface
func GreaterThanOrEqual ¶
func GreaterThanOrEqual(value interface{}) ConstraintInterface
func Identical ¶
func Identical(value interface{}) ConstraintInterface
func Length ¶
func Length(value uint) ConstraintInterface
func LessThan ¶
func LessThan(value interface{}) ConstraintInterface
func LessThanOrEqual ¶
func LessThanOrEqual(value interface{}) ConstraintInterface
func MaxLength ¶
func MaxLength(value uint) ConstraintInterface
func MinLength ¶
func MinLength(value uint) ConstraintInterface
func NotEqual ¶
func NotEqual(value interface{}) ConstraintInterface
func NotIdentical ¶
func NotIdentical(value interface{}) ConstraintInterface
func ParseTag ¶
func ParseTag(tag string) (constraints []ConstraintInterface, err error)
func Regexp ¶
func Regexp(expr string) ConstraintInterface
func RegexpCompiled ¶
func RegexpCompiled(re *regexp.Regexp) ConstraintInterface
func RegexpPOSIX ¶
func RegexpPOSIX(expr string) ConstraintInterface
type Each ¶
type Each []ConstraintInterface
type ErrorInterface ¶
type ErrorInterface interface { Error() string Errors() ValidationError }
type Map ¶
type Map map[interface{}][]ConstraintInterface
type Struct ¶
type Struct map[string][]ConstraintInterface
type TagOption ¶
func (TagOption) NoValue ¶
func (o TagOption) NoValue(lambda func() ConstraintInterface) (ConstraintInterface, error)
func (TagOption) WithBool ¶
func (o TagOption) WithBool(lambda func(v bool) ConstraintInterface) (ConstraintInterface, error)
func (TagOption) WithFloat ¶
func (o TagOption) WithFloat(lambda func(v float64) ConstraintInterface) (ConstraintInterface, error)
func (TagOption) WithInt ¶
func (o TagOption) WithInt(lambda func(v int64) ConstraintInterface) (ConstraintInterface, error)
func (TagOption) WithString ¶
func (o TagOption) WithString(lambda func(v string) ConstraintInterface) (ConstraintInterface, error)
func (TagOption) WithTag ¶
func (o TagOption) WithTag(lambda func(v []ConstraintInterface) ConstraintInterface) (ConstraintInterface, error)
func (TagOption) WithUint ¶
func (o TagOption) WithUint(lambda func(v uint64) ConstraintInterface) (ConstraintInterface, error)
func (TagOption) WithValue ¶
func (o TagOption) WithValue(lambda func(v interface{}) ConstraintInterface) (ConstraintInterface, error)
type ValidationError ¶
type ValidationError []*ConstraintError
func Validate ¶
func Validate(value interface{}, constraints ...ConstraintInterface) ValidationError
func ValidateSpecial ¶
func ValidateSpecial(value interface{}, constraints []ConstraintInterface, flags types.Flag) ValidationError
func (ValidationError) Error ¶
func (e ValidationError) Error() string
func (ValidationError) Errors ¶
func (e ValidationError) Errors() ValidationError
Click to show internal directories.
Click to hide internal directories.