validator

package
v0.0.0-...-e08aaa0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

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 (
	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 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

func (Each) Name

func (_ Each) Name() string

func (Each) Strict

func (_ Each) Strict() bool

func (Each) Validate

func (c Each) Validate(value interface{}, flags types.Flag) ErrorInterface

type ErrorInterface

type ErrorInterface interface {
	Error() string
	Errors() ValidationError
}

type Map

type Map map[interface{}][]ConstraintInterface

func (Map) Name

func (_ Map) Name() string

func (Map) Strict

func (_ Map) Strict() bool

func (Map) Validate

func (c Map) Validate(value interface{}, flags types.Flag) ErrorInterface

type Required

type Required bool

func (Required) Name

func (_ Required) Name() string

func (Required) Strict

func (_ Required) Strict() bool

func (Required) Validate

func (c Required) Validate(value interface{}, _ types.Flag) ErrorInterface

type Struct

type Struct map[string][]ConstraintInterface

func (Struct) Name

func (_ Struct) Name() string

func (Struct) Strict

func (_ Struct) Strict() bool

func (Struct) Validate

func (c Struct) Validate(value interface{}, flags types.Flag) ErrorInterface

type TagOption

type TagOption struct {
	Name   string
	Value  string
	Prefix string
}

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 (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 Timestamp

type Timestamp string

func (Timestamp) Name

func (_ Timestamp) Name() string

func (Timestamp) Strict

func (_ Timestamp) Strict() bool

func (Timestamp) Validate

func (c Timestamp) Validate(value interface{}, _ types.Flag) ErrorInterface

type Type

type Type string

func (Type) Name

func (_ Type) Name() string

func (Type) Strict

func (_ Type) Strict() bool

func (Type) Validate

func (c Type) Validate(value interface{}, _ types.Flag) ErrorInterface

type Valid

type Valid bool

func (Valid) Name

func (_ Valid) Name() string

func (Valid) Strict

func (_ Valid) Strict() bool

func (Valid) Validate

func (c Valid) Validate(value interface{}, _ types.Flag) ErrorInterface

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

Jump to

Keyboard shortcuts

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