From a887e395f3a477fbdfe14dfd3a9b8d5518445143 Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Tue, 7 Apr 2015 16:06:53 +0200 Subject: [PATCH] Fixes integration with "go-validate-yourself" http://stackoverflow.com/questions/29138591/hiding-nil-values-understanding-why-golang-fails-here --- binding/get_form.go | 5 ++++- binding/json.go | 5 ++++- binding/post_form.go | 5 ++++- binding/xml.go | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/binding/get_form.go b/binding/get_form.go index 7e0ea94a..a1717886 100644 --- a/binding/get_form.go +++ b/binding/get_form.go @@ -19,5 +19,8 @@ func (_ getFormBinding) Bind(req *http.Request, obj interface{}) error { if err := mapForm(obj, req.Form); err != nil { return err } - return _validator.ValidateStruct(obj) + if err := _validator.ValidateStruct(obj); err != nil { + return error(err) + } + return nil } diff --git a/binding/json.go b/binding/json.go index 6470e1d3..1f38618a 100644 --- a/binding/json.go +++ b/binding/json.go @@ -21,5 +21,8 @@ func (_ jsonBinding) Bind(req *http.Request, obj interface{}) error { if err := decoder.Decode(obj); err != nil { return err } - return _validator.ValidateStruct(obj) + if err := _validator.ValidateStruct(obj); err != nil { + return error(err) + } + return nil } diff --git a/binding/post_form.go b/binding/post_form.go index 0c876d78..dfd7381f 100644 --- a/binding/post_form.go +++ b/binding/post_form.go @@ -19,5 +19,8 @@ func (_ postFormBinding) Bind(req *http.Request, obj interface{}) error { if err := mapForm(obj, req.PostForm); err != nil { return err } - return _validator.ValidateStruct(obj) + if err := _validator.ValidateStruct(obj); err != nil { + return error(err) + } + return nil } diff --git a/binding/xml.go b/binding/xml.go index 69b38a6d..70f62932 100644 --- a/binding/xml.go +++ b/binding/xml.go @@ -20,5 +20,8 @@ func (_ xmlBinding) Bind(req *http.Request, obj interface{}) error { if err := decoder.Decode(obj); err != nil { return err } - return _validator.ValidateStruct(obj) + if err := _validator.ValidateStruct(obj); err != nil { + return error(err) + } + return nil }