diff --git a/README.md b/README.md index a316982..f22d29c 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ Package validator ================ [![Join the chat at https://gitter.im/bluesuncorp/validator](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/bluesuncorp/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![Build Status](https://semaphoreci.com/api/v1/projects/ec20115f-ef1b-4c7d-9393-cc76aba74eb4/517072/badge.svg)](https://semaphoreci.com/joeybloggs/validator) -[![Coverage Status](https://coveralls.io/repos/bluesuncorp/validator/badge.svg?branch=v7&service=github)](https://coveralls.io/github/bluesuncorp/validator?branch=v7) -[![GoDoc](https://godoc.org/gopkg.in/bluesuncorp/validator.v7?status.svg)](https://godoc.org/gopkg.in/bluesuncorp/validator.v7) +[![Build Status](https://semaphoreci.com/api/v1/projects/ec20115f-ef1b-4c7d-9393-cc76aba74eb4/523019/badge.svg)](https://semaphoreci.com/joeybloggs/validator) +[![Coverage Status](https://coveralls.io/repos/bluesuncorp/validator/badge.svg?branch=v8-development&service=github)](https://coveralls.io/github/bluesuncorp/validator?branch=v8-development) +[![GoDoc](https://godoc.org/gopkg.in/bluesuncorp/validator.v8?status.svg)](https://godoc.org/gopkg.in/bluesuncorp/validator.v8) Package validator implements value validations for structs and individual fields based on tags. diff --git a/examples/custom/custom.go b/examples/custom/custom.go index 51fa4b3..42054db 100644 --- a/examples/custom/custom.go +++ b/examples/custom/custom.go @@ -6,7 +6,7 @@ import ( "fmt" "reflect" - "gopkg.in/bluesuncorp/validator.v7" + "gopkg.in/bluesuncorp/validator.v8" ) // DbBackedUser User struct @@ -17,10 +17,7 @@ type DbBackedUser struct { func main() { - config := validator.Config{ - TagName: "validate", - ValidationFuncs: validator.BakedInValidators, - } + config := &validator.Config{TagName: "validate"} validate := validator.New(config) @@ -30,7 +27,7 @@ func main() { x := DbBackedUser{Name: sql.NullString{String: "", Valid: true}, Age: sql.NullInt64{Int64: 0, Valid: false}} errs := validate.Struct(x) - if len(errs) > 0 { + if errs != nil { fmt.Printf("Errs:\n%+v\n", errs) } } diff --git a/examples/simple/simple.go b/examples/simple/simple.go index c071318..b91610b 100644 --- a/examples/simple/simple.go +++ b/examples/simple/simple.go @@ -7,7 +7,7 @@ import ( sql "database/sql/driver" - "gopkg.in/bluesuncorp/validator.v7" + "gopkg.in/bluesuncorp/validator.v8" ) // User contains user information @@ -32,10 +32,7 @@ var validate *validator.Validate func main() { - config := validator.Config{ - TagName: "validate", - ValidationFuncs: validator.BakedInValidators, - } + config := &validator.Config{TagName: "validate"} validate = validator.New(config) @@ -67,7 +64,7 @@ func validateStruct() { fmt.Println(errs) // output: Key: "User.Age" Error:Field validation for "Age" failed on the "lte" tag // Key: "User.Addresses[0].City" Error:Field validation for "City" failed on the "required" tag - err := errs["User.Addresses[0].City"] + err := errs.(validator.ValidationErrors)["User.Addresses[0].City"] fmt.Println(err.Field) // output: City fmt.Println(err.Tag) // output: required fmt.Println(err.Kind) // output: string @@ -135,17 +132,10 @@ func ValidateValuerType(field reflect.Value) interface{} { func main2() { - customTypes := map[reflect.Type]validator.CustomTypeFunc{} - customTypes[reflect.TypeOf((*sql.Valuer)(nil))] = ValidateValuerType - customTypes[reflect.TypeOf(valuer{})] = ValidateValuerType - - config := validator.Config{ - TagName: "validate", - ValidationFuncs: validator.BakedInValidators, - CustomTypeFuncs: customTypes, - } + config := &validator.Config{TagName: "validate"} validate2 = validator.New(config) + validate2.RegisterCustomTypeFunc(ValidateValuerType, (*sql.Valuer)(nil), valuer{}) validateCustomFieldType() } diff --git a/examples_test.go b/examples_test.go index 3144bae..70129e8 100644 --- a/examples_test.go +++ b/examples_test.go @@ -3,8 +3,7 @@ package validator_test import ( "fmt" - // "gopkg.in/bluesuncorp/validator.v7" - "../validator" + "gopkg.in/bluesuncorp/validator.v8" ) func ExampleValidate_new() {