From 8573607cd60d7d9964f9821c007e1fbac513fc09 Mon Sep 17 00:00:00 2001 From: Toby Yan Date: Wed, 6 Mar 2019 15:25:54 +0800 Subject: [PATCH] let basecontroller binding could bind multiple tim https://github.com/gin-gonic/gin/pull/1341 Signed-off-by: Toby Yan --- http/controller/base_controller.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/http/controller/base_controller.go b/http/controller/base_controller.go index 9a6d509..93efc19 100644 --- a/http/controller/base_controller.go +++ b/http/controller/base_controller.go @@ -2,6 +2,7 @@ package controller import ( "github.com/gin-gonic/gin" + "github.com/gin-gonic/gin/binding" "gopkg.in/go-playground/validator.v9" "net/http" ) @@ -13,7 +14,7 @@ type Controller interface { type BaseController struct{} func (bc *BaseController) Validate(c *gin.Context, _validator interface{}) bool { - if err := c.ShouldBindJSON(_validator); err != nil { + if err := c.ShouldBindBodyWith(_validator, binding.JSON); err != nil { _ = err.(validator.ValidationErrors) //@todo translate