Documentation ¶
Index ¶
- func AddValidations(v ...Validation)
- func New() (cv *validate, err error)
- func SetTrans(trans string)
- func ValidateError(data any, message map[string]string) (bool, string)
- func ValidateMapError(data map[string]any, rules map[string]any, message map[string]string) (bool, string)
- func Var(data string, rule string) (bool, error)
- type Errors
- type Validation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateError ¶ added in v1.0.1002
验证器 返回验证器验证结果错误消息 和 bool (是否验证成功)
Types ¶
type Errors ¶ added in v1.0.1005
type Errors struct {
// contains filtered or unexported fields
}
错误信息
type Validation ¶
type Validation struct { // 标签名称 Tag string // 表示该标 Validate 的描述/解释 Translation string // 是否覆盖已存在的验证器 Override bool // 用于验证字段的函数 ValidateFn validator.Func // 翻译注册函数 RegisterFn validator.RegisterTranslationsFunc // 翻译函数 TranslationFn validator.TranslationFunc }
表示 validator.Validate 和 ut.Translator 的组合. 包含验证标签, 方式, 翻译器等基本要素 其中, tag 为必要字段
当存在 translation 时, 其他均为可选, 表示重写一个 tag 的翻译器
func ValidationOfRegexp ¶ added in v1.0.1005
func ValidationOfRegexp(tag string, regex string, translation string) Validation
创建正则验证器
func (*Validation) Register ¶ added in v1.0.1005
func (this *Validation) Register(v *validator.Validate, t ut.Translator) (err error)
注册关联验证器
func (Validation) RegisterCustom ¶ added in v1.0.1005
func (this Validation) RegisterCustom(v validate) error
func (*Validation) RegisterTranslation ¶ added in v1.0.1005
func (this *Validation) RegisterTranslation(v *validator.Validate, t ut.Translator) (err error)
以下方法支持
Click to show internal directories.
Click to hide internal directories.