Documentation ¶
Index ¶
- func AddToTranslatorFunc(tag string, translation string, override bool) validator.RegisterTranslationsFunc
- func And(fns ...validator.Func) validator.Func
- func ApplyTranslator(validator *validator.Validate, locTranslator locales.Translator, ...) (ut.Translator, error)
- func DateTimeValidator(layout string) validator.Func
- func DefaultTranslateFunc() validator.TranslationFunc
- func EnLocaleTranslator() locales.Translator
- func EqualValidator(p interface{}) validator.Func
- func FrLocaleTranslator() locales.Translator
- func GreaterThenOrEqualValidator(p interface{}) validator.Func
- func GreaterThenValidator(p interface{}) validator.Func
- func IdLocaleTranslator() locales.Translator
- func IsRequiredError(err error) bool
- func JaLocaleTranslator() locales.Translator
- func LenValidator(p interface{}) validator.Func
- func LengthInRangeValidator(min, max interface{}) validator.Func
- func LengthOutOfRangeValidator(min, max interface{}) validator.Func
- func LessThenOrEqualValidator(p interface{}) validator.Func
- func LessThenValidator(p interface{}) validator.Func
- func NlLocaleTranslator() locales.Translator
- func NotEqualValidator(p interface{}) validator.Func
- func OneofValidator(ps ...interface{}) validator.Func
- func Or(fns ...validator.Func) validator.Func
- func ParamRegexpValidator() validator.Func
- func PtBrLocaleTranslator() locales.Translator
- func RegexpValidator(re *regexp.Regexp) validator.Func
- func RuLocaleTranslator() locales.Translator
- func TrLocaleTranslator() locales.Translator
- func ZhHantLocaleTranslator() locales.Translator
- func ZhLocaleTranslator() locales.Translator
- type TranslationRegisterHandler
- func EnTranslationRegisterFunc() TranslationRegisterHandler
- func FrTranslationRegisterFunc() TranslationRegisterHandler
- func IdTranslationRegisterFunc() TranslationRegisterHandler
- func JaTranslationRegisterFunc() TranslationRegisterHandler
- func NlTranslationRegisterFunc() TranslationRegisterHandler
- func PtBrTranslationRegisterFunc() TranslationRegisterHandler
- func RuTranslationRegisterFunc() TranslationRegisterHandler
- func TrTranslationRegisterFunc() TranslationRegisterHandler
- func ZhTranslationRegisterFunc() TranslationRegisterHandler
- func ZhTwTranslationRegisterFunc() TranslationRegisterHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddToTranslatorFunc ¶
func AddToTranslatorFunc(tag string, translation string, override bool) validator.RegisterTranslationsFunc
AddToTranslatorFunc returns a validator.RegisterTranslationsFunc function, it uses the given tag, translation and override parameters to **register translation information** for a ut.Translator and will be used within the validator.TranslationFunc.
This function can be used for validator.Validate RegisterTranslation() method's translationFn (the second) parameter, also see ApplyTranslator.
func And ¶
func And(fns ...validator.Func) validator.Func
And represents the intersection of multiple validator, just like ',' in validator tag.
func ApplyTranslator ¶
func ApplyTranslator(validator *validator.Validate, locTranslator locales.Translator, registerFn TranslationRegisterHandler) (ut.Translator, error)
ApplyTranslator applies translator to validator.Validate using given locales.Translator and TranslationRegisterHandler, and returns a ut.Translator (universal translator). Also see xvalidator.AddToTranslatorFunc and xvalidator.DefaultTranslateFunc.
Note:
1. locales.Translator can be get from en.New(), zh.New() and so on, here `en` and `zh` packages are from github.com/go-playground/locales. These kind of values can also be get from xvalidator.EnLocaleTranslator, xvalidator.ZhLocaleTranslator and so on.
2. xvalidator.TranslationRegisterHandler can be get from en.RegisterDefaultTranslations, zh.RegisterDefaultTranslations and so on, here `en` and `zh` packages are from github.com/go-playground/validator/v10/translations. These kind of values can also be get from xvalidator.EnTranslationRegisterFunc, xvalidator.ZhTranslationRegisterFunc and so on.
Example:
validator := validator.New() // apply default translation to validator translator := xvalidator.ApplyTranslator(validator, xvalidator.EnLocaleTranslator(), xvalidator.EnTranslationRegisterFunc()) // ut.Translator // use validator.RegisterTranslationsFunc and validator.TranslationFunc to register translation translationFunc := xvalidator.AddToTranslatorFunc("tag", "{0} has {1}", false) // validator.RegisterTranslationsFunc validator.RegisterTranslation("tag", translator, translationFunc, xvalidator.DefaultTranslateFunc())
func DateTimeValidator ¶
func DateTimeValidator(layout string) validator.Func
DateTimeValidator represents datetime validator using given layout.
func DefaultTranslateFunc ¶
func DefaultTranslateFunc() validator.TranslationFunc
DefaultTranslateFunc returns a validator.TranslationFunc function, it uses the field name (validator.FieldError's field) as the first parameter ({0}), and the field param (validator.FieldError's param) as the second parameter ({1}) to **create translation for the given tag**.
This function can be used for validator.Validate RegisterTranslation() method's registerFn (the third) parameter, also see ApplyTranslator.
func EnLocaleTranslator ¶
func EnLocaleTranslator() locales.Translator
EnLocaleTranslator is a locales.Translator for en.New() from github.com/go-playground/locales/en.
func EqualValidator ¶
func EqualValidator(p interface{}) validator.Func
EqualValidator represents `eq` validator tag. See https://godoc.org/github.com/go-playground/validator#hdr-Equals. For strings & numbers, eq will ensure that the value is equal to the parameter given. For slices, arrays, and maps, validates the number of items.
func FrLocaleTranslator ¶
func FrLocaleTranslator() locales.Translator
FrLocaleTranslator is a locales.Translator for fr.New() from github.com/go-playground/locales/fr.
func GreaterThenOrEqualValidator ¶
func GreaterThenOrEqualValidator(p interface{}) validator.Func
GreaterThenOrEqualValidator represents `gte` validator tag. See https://godoc.org/github.com/go-playground/validator#hdr-Greater_Than_or_Equal. For numbers, gte will ensure that the value is greater or equal to the parameter given. For strings, it checks that the string length is at least that number of characters. For slices, arrays, and maps, validates the number of items.
func GreaterThenValidator ¶
func GreaterThenValidator(p interface{}) validator.Func
GreaterThenValidator represents `gt` validator tag. See https://godoc.org/github.com/go-playground/validator#hdr-Greater_Than. For numbers, this will ensure that the value is greater than the parameter given. For strings, it checks that the string length is greater than that number of characters. For slices, arrays and maps it validates the number of items.
func IdLocaleTranslator ¶
func IdLocaleTranslator() locales.Translator
IdLocaleTranslator is a locales.Translator for id.New() from github.com/go-playground/locales/id.
func IsRequiredError ¶
IsRequiredError returns true if the error is validator.ValidationErrors with required tag.
func JaLocaleTranslator ¶
func JaLocaleTranslator() locales.Translator
JaLocaleTranslator is a locales.Translator for ja.New() from github.com/go-playground/locales/ja.
func LenValidator ¶
func LenValidator(p interface{}) validator.Func
LenValidator represents `len` validator tag. See https://godoc.org/github.com/go-playground/validator#hdr-Length. For numbers, length will ensure that the value is equal to the parameter given. For strings, it checks that the string length is exactly that number of characters. For slices, arrays, and maps, validates the number of items.
func LengthInRangeValidator ¶
func LengthInRangeValidator(min, max interface{}) validator.Func
LengthInRangeValidator represents `min,max` validator tag, equals to combine GreaterThenOrEqualValidator and LessThenOrEqualValidator with And.
func LengthOutOfRangeValidator ¶
func LengthOutOfRangeValidator(min, max interface{}) validator.Func
LengthOutOfRangeValidator represents `min|max` validator tag, equals to combine GreaterThenOrEqualValidator and LessThenOrEqualValidator with Or.
func LessThenOrEqualValidator ¶
func LessThenOrEqualValidator(p interface{}) validator.Func
LessThenOrEqualValidator represents `lte` validator tag. See https://godoc.org/github.com/go-playground/validator#hdr-Less_Than_or_Equal. For numbers, lte will ensure that the value is less than or equal to the parameter given. For strings, it checks that the string length is at most that number of characters. For slices, arrays, and maps, validates the number of items.
func LessThenValidator ¶
func LessThenValidator(p interface{}) validator.Func
LessThenValidator represents `lt` validator tag. See https://godoc.org/github.com/go-playground/validator#hdr-Less_Than. For numbers, this will ensure that the value is less than the parameter given. For strings, it checks that the string length is less than that number of characters. For slices, arrays, and maps it validates the number of items.
func NlLocaleTranslator ¶
func NlLocaleTranslator() locales.Translator
NlLocaleTranslator is a locales.Translator for nl.New() from github.com/go-playground/locales/nl.
func NotEqualValidator ¶
func NotEqualValidator(p interface{}) validator.Func
NotEqualValidator represents `ne` validator tag. See https://godoc.org/github.com/go-playground/validator#hdr-Not_Equal. For strings & numbers, ne will ensure that the value is not equal to the parameter given. For slices, arrays, and maps, validates the number of items.
func OneofValidator ¶
func OneofValidator(ps ...interface{}) validator.Func
OneofValidator represents `oneof` validator tag. See https://godoc.org/github.com/go-playground/validator#hdr-One_Of. For strings, ints, uints, and floats, oneof will ensure that the value is one of the values in the parameter.
func Or ¶
func Or(fns ...validator.Func) validator.Func
Or represents the union of multiple validator, just like '|' in validator tag. See https://godoc.org/github.com/go-playground/validator#hdr-Or_Operator.
func ParamRegexpValidator ¶
func ParamRegexpValidator() validator.Func
ParamRegexpValidator represents regexp validator with param, just like `regexp: xxx`.
func PtBrLocaleTranslator ¶
func PtBrLocaleTranslator() locales.Translator
PtBrLocaleTranslator is a locales.Translator for pt_BR.New() from github.com/go-playground/locales/pt_BR.
func RegexpValidator ¶
RegexpValidator represents regexp validator using given regexp.
func RuLocaleTranslator ¶
func RuLocaleTranslator() locales.Translator
RuLocaleTranslator is a locales.Translator for ru.New() from github.com/go-playground/locales/ru.
func TrLocaleTranslator ¶
func TrLocaleTranslator() locales.Translator
TrLocaleTranslator is a locales.Translator for tr.New() from github.com/go-playground/locales/tr.
func ZhHantLocaleTranslator ¶
func ZhHantLocaleTranslator() locales.Translator
ZhHantLocaleTranslator is a locales.Translator for zh_Hant.New() from github.com/go-playground/locales/zh_Hant.
func ZhLocaleTranslator ¶
func ZhLocaleTranslator() locales.Translator
ZhLocaleTranslator is a locales.Translator for zh.New() from github.com/go-playground/locales/zh.
Types ¶
type TranslationRegisterHandler ¶
type TranslationRegisterHandler func(v *validator.Validate, trans ut.Translator) error
TranslationRegisterHandler represents a translation register function, which is the type of en.RegisterDefaultTranslations, zh.RegisterDefaultTranslations and so on, here `en` and `zh` packages are from github.com/go-playground/validator/v10/translations.
These kind of values can be get from xvalidator.EnTranslationRegisterFunc, xvalidator.ZhTranslationRegisterFunc and so on.
func EnTranslationRegisterFunc ¶
func EnTranslationRegisterFunc() TranslationRegisterHandler
EnTranslationRegisterFunc is a TranslationRegisterHandler for en.RegisterDefaultTranslations. From github.com/go-playground/validator/v10/translations/en.
func FrTranslationRegisterFunc ¶
func FrTranslationRegisterFunc() TranslationRegisterHandler
FrTranslationRegisterFunc is a TranslationRegisterHandler for fr.RegisterDefaultTranslations. From github.com/go-playground/validator/v10/translations/fr.
func IdTranslationRegisterFunc ¶
func IdTranslationRegisterFunc() TranslationRegisterHandler
IdTranslationRegisterFunc is a TranslationRegisterHandler for id.RegisterDefaultTranslations. From github.com/go-playground/validator/v10/translations/id.
func JaTranslationRegisterFunc ¶
func JaTranslationRegisterFunc() TranslationRegisterHandler
JaTranslationRegisterFunc is a TranslationRegisterHandler for ja.RegisterDefaultTranslations. From github.com/go-playground/validator/v10/translations/ja.
func NlTranslationRegisterFunc ¶
func NlTranslationRegisterFunc() TranslationRegisterHandler
NlTranslationRegisterFunc is a TranslationRegisterHandler for nl.RegisterDefaultTranslations. From github.com/go-playground/validator/v10/translations/nl.
func PtBrTranslationRegisterFunc ¶
func PtBrTranslationRegisterFunc() TranslationRegisterHandler
PtBrTranslationRegisterFunc is a TranslationRegisterHandler for pt_BR.RegisterDefaultTranslations. From github.com/go-playground/validator/v10/translations/pt_BR.
func RuTranslationRegisterFunc ¶
func RuTranslationRegisterFunc() TranslationRegisterHandler
RuTranslationRegisterFunc is a TranslationRegisterHandler for ru.RegisterDefaultTranslations. From github.com/go-playground/validator/v10/translation/ru.
func TrTranslationRegisterFunc ¶
func TrTranslationRegisterFunc() TranslationRegisterHandler
TrTranslationRegisterFunc is a TranslationRegisterHandler for tr.RegisterDefaultTranslations. From github.com/go-playground/validator/v10/translations/tr.
func ZhTranslationRegisterFunc ¶
func ZhTranslationRegisterFunc() TranslationRegisterHandler
ZhTranslationRegisterFunc is a TranslationRegisterHandler for zh.RegisterDefaultTranslations. From github.com/go-playground/validator/v10/translations/zh.
func ZhTwTranslationRegisterFunc ¶
func ZhTwTranslationRegisterFunc() TranslationRegisterHandler
ZhTwTranslationRegisterFunc is a TranslationRegisterHandler for zh_tw.RegisterDefaultTranslations. From github.com/go-playground/validator/v10/translations/zh_tw.