From 0c9f086b7496e38f39a96246fe9cb30049d99f28 Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Sun, 31 May 2015 16:30:00 +0200 Subject: [PATCH] Renames Validate() to validate() --- binding/binding.go | 2 +- binding/default_validator.go | 4 +++- binding/form.go | 2 +- binding/json.go | 2 +- binding/validate_test.go | 14 +++++++------- binding/xml.go | 2 +- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/binding/binding.go b/binding/binding.go index 968e898e..f719fbc1 100644 --- a/binding/binding.go +++ b/binding/binding.go @@ -53,7 +53,7 @@ func Default(method, contentType string) Binding { } } -func Validate(obj interface{}) error { +func validate(obj interface{}) error { if Validator == nil { return nil } diff --git a/binding/default_validator.go b/binding/default_validator.go index fe29222d..7f12152b 100644 --- a/binding/default_validator.go +++ b/binding/default_validator.go @@ -17,7 +17,9 @@ var _ StructValidator = &defaultValidator{} func (v *defaultValidator) ValidateStruct(obj interface{}) error { if kindOfData(obj) == reflect.Struct { v.lazyinit() - return v.validate.Struct(obj) + if err := v.validate.Struct(obj); err != nil { + return error(err) + } } return nil } diff --git a/binding/form.go b/binding/form.go index 0cfe8741..ff00b0df 100644 --- a/binding/form.go +++ b/binding/form.go @@ -20,5 +20,5 @@ func (_ formBinding) Bind(req *http.Request, obj interface{}) error { if err := mapForm(obj, req.Form); err != nil { return err } - return Validate(obj) + return validate(obj) } diff --git a/binding/json.go b/binding/json.go index a21192c0..25c5a06c 100644 --- a/binding/json.go +++ b/binding/json.go @@ -21,5 +21,5 @@ func (_ jsonBinding) Bind(req *http.Request, obj interface{}) error { if err := decoder.Decode(obj); err != nil { return err } - return Validate(obj) + return validate(obj) } diff --git a/binding/validate_test.go b/binding/validate_test.go index f4854105..27ba7b66 100644 --- a/binding/validate_test.go +++ b/binding/validate_test.go @@ -49,7 +49,7 @@ func createStruct() struct3 { func TestValidateGoodObject(t *testing.T) { test := createStruct() - assert.Nil(t, Validate(&test)) + assert.Nil(t, validate(&test)) } type Object map[string]interface{} @@ -60,10 +60,10 @@ func TestValidateSlice(t *testing.T) { var obj2 Object var nu = 10 - assert.NoError(t, Validate(obj)) - assert.NoError(t, Validate(&obj)) - assert.NoError(t, Validate(obj2)) - assert.NoError(t, Validate(&obj2)) - assert.NoError(t, Validate(nu)) - assert.NoError(t, Validate(&nu)) + assert.NoError(t, validate(obj)) + assert.NoError(t, validate(&obj)) + assert.NoError(t, validate(obj2)) + assert.NoError(t, validate(&obj2)) + assert.NoError(t, validate(nu)) + assert.NoError(t, validate(&nu)) } diff --git a/binding/xml.go b/binding/xml.go index 6140ab1e..cac4be89 100644 --- a/binding/xml.go +++ b/binding/xml.go @@ -20,5 +20,5 @@ func (_ xmlBinding) Bind(req *http.Request, obj interface{}) error { if err := decoder.Decode(obj); err != nil { return err } - return Validate(obj) + return validate(obj) }