Using "validator.v5"
This commit is contained in:
		| @ -7,7 +7,7 @@ package binding | |||||||
| import ( | import ( | ||||||
| 	"net/http" | 	"net/http" | ||||||
|  |  | ||||||
| 	"gopkg.in/joeybloggs/go-validate-yourself.v4" | 	"gopkg.in/bluesuncorp/validator.v5" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| const ( | const ( | ||||||
| @ -25,7 +25,7 @@ type Binding interface { | |||||||
| 	Bind(*http.Request, interface{}) error | 	Bind(*http.Request, interface{}) error | ||||||
| } | } | ||||||
|  |  | ||||||
| var _validator = validator.NewValidator("binding", validator.BakedInValidators) | var validate = validator.New("binding", validator.BakedInValidators) | ||||||
|  |  | ||||||
| var ( | var ( | ||||||
| 	JSON = jsonBinding{} | 	JSON = jsonBinding{} | ||||||
| @ -48,8 +48,15 @@ func Default(method, contentType string) Binding { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func Validate(obj interface{}) error { | func ValidateField(f interface{}, tag string) error { | ||||||
| 	if err := _validator.ValidateStruct(obj); err != nil { | 	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 error(err) | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user