validator

package
v0.0.0-...-bfcc399 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VALIDATOR_ASSIGNMENT_SIGN   = "="
	VALIDATOR_PARAMS_SPLIT_SIGN = "|"
	VALIDATOR_PLACEHOLDER_SIGN  = "_"
	VALIDATOR_SPLIT_SIGN        = "||"
)
View Source
const (
	EQUAL_ERR = "[name] should be equal [value]"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolValidator

type BoolValidator struct {
	Equal
}

BoolValidator

func (*BoolValidator) Validate

func (bv *BoolValidator) Validate(field string, value reflect.Value, isRequired bool, args ...string) error

type Equal

type Equal struct {
}

func (*Equal) MultiEqual

func (e *Equal) MultiEqual(field string, value reflect.Value, args ...string) error

func (*Equal) ValueEqual

func (e *Equal) ValueEqual(field string, value reflect.Value, vl string) error

判断 String/Bool/Int/Int8/Int16/Int32/Int64/Uint/Uint8/Uint16/Uint32/Uint64/Float32/Float64

type IValidator

type IValidator interface {
	Validate(field string, value reflect.Value, isRequired bool, args ...string) error
}

type InValidator

type InValidator struct {
	Equal
}

InValidator 仅支持 string,float,int,bool 类型 或值类型为 string,float,int,bool 类型的array,slice,map

func (*InValidator) Validate

func (iv *InValidator) Validate(field string, value reflect.Value, isRequired bool, args ...string) (err error)

type Kind

type Kind uint
const (
	TYPE_INVALID   = "[name] type invalid"
	PARAMS_INVALID = "[name] params invalid"

	STRUCT_EMPTY              = "struct %v is empty"
	VALIDATOR_ALREADY_EXISTED = "[%s] validator already existed"

	Int_Kind Kind = iota
	Int8_Kind
	Int16_Kind
	Int32_Kind
	Int64_Kind
	Uint_Kind
	Uint8_Kind
	Uint16_Kind
	Uint32_Kind
	Uint64_Kind
	Float32_Kind
	Float64_Kind
	Array_Kind
	Slice_Kind
	Map_Kind
	Chan_Kind
	String_Kind
)

type LenValidator

type LenValidator struct {
	Equal
}

LenValidator

func (*LenValidator) Validate

func (lv *LenValidator) Validate(field string, value reflect.Value, isRequired bool, args ...string) error

type MultiValidator

type MultiValidator struct {
	Equal
	Range
}

MultiValidator

func (*MultiValidator) Validate

func (av *MultiValidator) Validate(field string, value reflect.Value, isRequired bool, args ...string) error

type NumberValidator

type NumberValidator struct {
	Equal
	Range
}

NumberValidator

func (*NumberValidator) Validate

func (nv *NumberValidator) Validate(field string, value reflect.Value, isRequired bool, args ...string) error

type Range

type Range struct {
	// contains filtered or unexported fields
}

func (*Range) CompareMultiRange

func (r *Range) CompareMultiRange(value reflect.Value) error

func (*Range) CompareNumberRange

func (r *Range) CompareNumberRange(value reflect.Value) (err error)

func (*Range) CompareStringRange

func (r *Range) CompareStringRange(value reflect.Value) error

func (*Range) InitRange

func (r *Range) InitRange(field string, args ...string)

type RequiredValidator

type RequiredValidator struct {
}

RequiredValidator

func (*RequiredValidator) Validate

func (rv *RequiredValidator) Validate(field string, value reflect.Value, isRequired bool, args ...string) error

type StringValidator

type StringValidator struct {
	Equal
	Range
}

StringValidator

func (*StringValidator) Validate

func (sv *StringValidator) Validate(field string, value reflect.Value, isRequired bool, args ...string) error

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

func NewValidator

func NewValidator() *Validator

func (*Validator) AddValidator

func (v *Validator) AddValidator(key string, validator IValidator) error

添加验证器

func (*Validator) LazyValidate

func (v *Validator) LazyValidate(a interface{}) error

func (*Validator) Validate

func (v *Validator) Validate(a interface{}) (errs []error)

Jump to

Keyboard shortcuts

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