ShouldBind才会报翻译的错误, 现将翻译的代码移动到 ShouldBindWith这个最根本的函数下
This commit is contained in:
parent
bf312432ee
commit
0d83cfc042
11
gin/b/b.go
11
gin/b/b.go
|
@ -21,7 +21,12 @@ func ShouldBind(req *http.Request, obj interface{}) error {
|
|||
return err
|
||||
}
|
||||
b := binding.Default(req.Method, content)
|
||||
err = ShouldBindWith(req, obj, b)
|
||||
return ShouldBindWith(req, obj, b)
|
||||
|
||||
}
|
||||
|
||||
func ShouldBindWith(req *http.Request, obj interface{}, b binding.Binding) error {
|
||||
err := b.Bind(req, obj)
|
||||
errs, ok := err.(validator.ValidationErrors)
|
||||
if !ok {
|
||||
// 非validator.ValidationErrors类型错误直接返回
|
||||
|
@ -29,10 +34,6 @@ func ShouldBind(req *http.Request, obj interface{}) error {
|
|||
}
|
||||
return errs.Translate(binding.ValidTrans)
|
||||
}
|
||||
|
||||
func ShouldBindWith(req *http.Request, obj interface{}, b binding.Binding) error {
|
||||
return b.Bind(req, obj)
|
||||
}
|
||||
func ShouldBindJSON(req *http.Request, obj interface{}) error {
|
||||
return ShouldBindWith(req, obj, binding.JSON)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue