diff --git a/gin/b/b.go b/gin/b/b.go index b341c43..784d14b 100644 --- a/gin/b/b.go +++ b/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) }