github.com/bytedance/go-tagexpr@v2.7.5-0.20210114074101-de5b8743ad85+incompatible/validator/default.go (about) 1 package validator 2 3 var defaultValidator = New("vd").SetErrorFactory(defaultErrorFactory) 4 5 // Default returns the default validator. 6 // NOTE: 7 // The tag name is 'vd' 8 func Default() *Validator { 9 return defaultValidator 10 } 11 12 // Validate uses the default validator to validate whether the fields of value is valid. 13 // NOTE: 14 // The tag name is 'vd' 15 // If checkAll=true, validate all the error. 16 func Validate(value interface{}, checkAll ...bool) error { 17 return defaultValidator.Validate(value, checkAll...) 18 } 19 20 // SetErrorFactory customizes the factory of validation error for the default validator. 21 // NOTE: 22 // The tag name is 'vd' 23 func SetErrorFactory(errFactory func(fieldSelector, msg string) error) { 24 defaultValidator.SetErrorFactory(errFactory) 25 }