Documentation ¶
Index ¶
- Variables
- func Middleware(skipper ...echo.Skipper) echo.MiddlewareFunc
- func NormalizeLocale(locale string) string
- func RangeCustomValidation(fn func(tag string, v *CustomValidation))
- func RegisterCustomValidation(tag string, fn validator.FuncCtx, options ...CustomValidationOption)
- func RegisterTranslation(translator locales.Translator, register TranslationRegister, locales ...string)
- func UniversalTranslator() *ut.UniversalTranslator
- type CustomValidation
- type CustomValidationOption
- type Translation
- type TranslationRegister
- type Validate
- func (v *Validate) Context() echo.Context
- func (v *Validate) Error(err error) error
- func (v *Validate) Object() *validator.Validate
- func (v *Validate) RegisterTranslation(tag string, trans ut.Translator, registerFn validator.RegisterTranslationsFunc, ...) error
- func (v *Validate) Struct(i interface{}) error
- func (v *Validate) StructExcept(s interface{}, fields ...string) error
- func (v *Validate) StructFiltered(s interface{}, fn validator.FilterFunc) error
- func (v *Validate) StructPartial(s interface{}, fields ...string) error
- func (v *Validate) Validate(i interface{}, args ...interface{}) echo.ValidateResult
- func (v *Validate) ValidateMap(data map[string]interface{}, rules map[string]interface{}) map[string]interface{}
- func (v *Validate) Var(field interface{}, tag string) error
- func (v *Validate) VarWithValue(field interface{}, other interface{}, tag string) error
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultLocale = `zh`
View Source
var SupportedLocales []locales.Translator = []locales.Translator{ locale_zh.New(), locale_en.New(), locale_enUS.New(), locale_fr.New(), locale_ru.New(), locale_jaJP.New(), }
View Source
var Translations = map[string]TranslationRegister{ `zh`: translation_zh.RegisterDefaultTranslations, `ru`: translation_ru.RegisterDefaultTranslations, `ja`: translation_ja.RegisterDefaultTranslations, `en`: translation_en.RegisterDefaultTranslations, `fr`: translation_fr.RegisterDefaultTranslations, }
Functions ¶
func Middleware ¶
func Middleware(skipper ...echo.Skipper) echo.MiddlewareFunc
func NormalizeLocale ¶
func RangeCustomValidation ¶ added in v0.2.0
func RangeCustomValidation(fn func(tag string, v *CustomValidation))
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
Types ¶
type CustomValidation ¶ added in v0.0.2
type CustomValidation struct { Tag string Func validator.FuncCtx CallIfNull bool Translations map[string]*Translation }
func GetCustomValidation ¶ added in v0.2.0
func GetCustomValidation(tag string) *CustomValidation
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 TranslationRegister ¶
type TranslationRegister func(v *validator.Validate, trans ut.Translator) (err error)
type Validate ¶
type Validate struct {
// contains filtered or unexported fields
}
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) StructExcept ¶
StructExcept 校验struct中的选项,不过除了fields里所给的字段
func (*Validate) StructFiltered ¶
StructFiltered 接收一个struct和一个函数,这个函数的返回值为bool,决定是否跳过该选项
func (*Validate) StructPartial ¶
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) VarWithValue ¶
VarWithValue 将两个变量进行对比,比如 validate.VarWithValue(s1, s2, "eqcsfield")
Click to show internal directories.
Click to hide internal directories.