File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -24,17 +24,22 @@ type ValidError struct {
2424 Message string
2525}
2626
27+ var trans ut.Translator
28+
29+ func init () {
30+ uni := ut .New (zh .New ())
31+ trans , _ = uni .GetTranslator ("zh" )
32+ v , ok := binding .Validator .Engine ().(* val.Validate )
33+ if ok {
34+ _ = zhTranslations .RegisterDefaultTranslations (v , trans )
35+ }
36+ }
37+
2738func BindAndValid (c * gin.Context , target interface {}) bool {
2839 errs := make (map [string ]string )
2940 err := c .ShouldBindJSON (target )
3041 if err != nil {
3142 log .Println ("raw err" , err )
32- uni := ut .New (zh .New ())
33- trans , _ := uni .GetTranslator ("zh" )
34- v , ok := binding .Validator .Engine ().(* val.Validate )
35- if ok {
36- _ = zhTranslations .RegisterDefaultTranslations (v , trans )
37- }
3843
3944 verrs , ok := err .(val.ValidationErrors )
4045
You can’t perform that action at this time.
0 commit comments