From 0d83cfc0428be6c7792e9a17ce8585880efd6f58 Mon Sep 17 00:00:00 2001 From: gamife Date: Sat, 5 Dec 2020 16:19:04 +0800 Subject: [PATCH] =?UTF-8?q?ShouldBind=E6=89=8D=E4=BC=9A=E6=8A=A5=E7=BF=BB?= =?UTF-8?q?=E8=AF=91=E7=9A=84=E9=94=99=E8=AF=AF,=20=E7=8E=B0=E5=B0=86?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E7=9A=84=E4=BB=A3=E7=A0=81=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E5=88=B0=20ShouldBindWith=E8=BF=99=E4=B8=AA=E6=9C=80=E6=A0=B9?= =?UTF-8?q?=E6=9C=AC=E7=9A=84=E5=87=BD=E6=95=B0=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gin/b/b.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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) }