package module
Version: v0.1.2 Latest Latest

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

Go to latest
Published: Aug 16, 2021 License: MIT Imports: 20 Imported by: 0






This section is empty.


View Source
var CustomValidations = map[string]*CustomValidation{}
View Source
var DefaultLocale = `zh`


func Middleware

func Middleware(skipper ...echo.Skipper) echo.MiddlewareFunc

func NormalizeLocale

func NormalizeLocale(locale string) string

func RegisterCustomValidation added in v0.0.2

func RegisterCustomValidation(tag string, fn validator.FuncCtx, options ...CustomValidationOption)

func RegisterTranslation

func RegisterTranslation(translator locales.Translator, register TranslationRegister, locales ...string)

func UniversalTranslator

func UniversalTranslator() *ut.UniversalTranslator


type CustomValidation added in v0.0.2

type CustomValidation struct {
	Tag          string
	Func         validator.FuncCtx
	CallIfNull   bool
	Translations map[string]*Translation

func NewCustomValidation added in v0.0.3

func NewCustomValidation(tag string, fn validator.FuncCtx, options ...CustomValidationOption) *CustomValidation

func (*CustomValidation) Register added in v0.0.3

func (v *CustomValidation) Register(validate *Validate, translator ut.Translator, locale string)

type CustomValidationOption added in v0.0.3

type CustomValidationOption func(*CustomValidation)

func OptCallIfNull added in v0.0.3

func OptCallIfNull(on bool) CustomValidationOption

func OptTranslation added in v0.0.3

func OptTranslation(locale string, translation *Translation) CustomValidationOption

func OptTranslations added in v0.0.3

func OptTranslations(translations map[string]*Translation) CustomValidationOption

type Translation added in v0.0.3

type Translation struct {
	Text     string //{0}必须是一个有效的ISBN编号
	Override bool

type TranslationRegister

type TranslationRegister func(v *validator.Validate, trans ut.Translator) (err error)

type Validate

type Validate struct {
	// contains filtered or unexported fields

func New

func New(ctx echo.Context, locales ...string) *Validate

func (*Validate) Context added in v0.1.0

func (v *Validate) Context() echo.Context

func (*Validate) Error

func (v *Validate) Error(err error) error

func (*Validate) Object

func (v *Validate) Object() *validator.Validate

func (*Validate) RegisterTranslation added in v0.1.0

func (v *Validate) RegisterTranslation(tag string, trans ut.Translator, registerFn validator.RegisterTranslationsFunc, translationFn validator.TranslationFunc) error

RegisterTranslation 添加额外翻译

func (*Validate) Struct

func (v *Validate) Struct(i interface{}) error

Struct 接收的参数为一个struct

func (*Validate) StructExcept

func (v *Validate) StructExcept(s interface{}, fields ...string) error

StructExcept 校验struct中的选项,不过除了fields里所给的字段

func (*Validate) StructFiltered

func (v *Validate) StructFiltered(s interface{}, fn validator.FilterFunc) error

StructFiltered 接收一个struct和一个函数,这个函数的返回值为bool,决定是否跳过该选项

func (*Validate) StructPartial

func (v *Validate) StructPartial(s interface{}, fields ...string) error

StructPartial 接收一个struct和fields,仅校验在fields里的值

func (*Validate) Validate

func (v *Validate) Validate(i interface{}, args ...interface{}) echo.ValidateResult

Validate 此处支持两种用法: 1. Validate(表单字段名, 表单值, 验证规则名) 2. Validate(结构体实例, 要验证的结构体字段1,要验证的结构体字段2) Validate(结构体实例) 代表验证所有带“valid”标签的字段

func (*Validate) ValidateMap

func (v *Validate) ValidateMap(data map[string]interface{}, rules map[string]interface{}) map[string]interface{}

ValidateMap validates map data form a map of tags

func (*Validate) Var

func (v *Validate) Var(field interface{}, tag string) error

Var 接收一个变量和一个tag的值,比如 validate.Var(i, "gt=1,lt=10")

func (*Validate) VarWithValue

func (v *Validate) VarWithValue(field interface{}, other interface{}, tag string) error

VarWithValue 将两个变量进行对比,比如 validate.VarWithValue(s1, s2, "eqcsfield")

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL