Renames Validate() to validate()

This commit is contained in:
Manu Mtz-Almeida 2015-05-31 16:30:00 +02:00
parent fecde9fed6
commit 0c9f086b74
6 changed files with 14 additions and 12 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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))
}

View File

@ -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)
}