From 8549810e2e88fa01c775981374656245c86ddaca Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Fri, 22 May 2015 16:46:21 +0200 Subject: [PATCH] Using "validator.v5" --- binding/binding.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/binding/binding.go b/binding/binding.go index 4a7eb8f..40fc2ae 100644 --- a/binding/binding.go +++ b/binding/binding.go @@ -7,7 +7,7 @@ package binding import ( "net/http" - "gopkg.in/joeybloggs/go-validate-yourself.v4" + "gopkg.in/bluesuncorp/validator.v5" ) const ( @@ -25,7 +25,7 @@ type Binding interface { Bind(*http.Request, interface{}) error } -var _validator = validator.NewValidator("binding", validator.BakedInValidators) +var validate = validator.New("binding", validator.BakedInValidators) var ( JSON = jsonBinding{} @@ -48,8 +48,15 @@ func Default(method, contentType string) Binding { } } -func Validate(obj interface{}) error { - if err := _validator.ValidateStruct(obj); err != nil { +func ValidateField(f interface{}, tag string) error { + if err := validate.Field(f, tag); err != nil { + return error(err) + } + return nil +} + +func Validate(obj interface{}) error { + if err := validate.Struct(obj); err != nil { return error(err) } return nil