Skip to content

Commit 1a791b5

Browse files
Dean KarnDean Karn
authored andcommitted
Merge pull request #171 from bluesuncorp/v8-development
V8 development
2 parents 40bd6a0 + 0f4bcfc commit 1a791b5

File tree

4 files changed

+12
-26
lines changed

4 files changed

+12
-26
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ Package validator
22
================
33

44
[![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)
5-
[![Build Status](https://semaphoreci.com/api/v1/projects/ec20115f-ef1b-4c7d-9393-cc76aba74eb4/517072/badge.svg)](https://semaphoreci.com/joeybloggs/validator)
6-
[![Coverage Status](https://coveralls.io/repos/bluesuncorp/validator/badge.svg?branch=v7&service=github)](https://coveralls.io/github/bluesuncorp/validator?branch=v7)
7-
[![GoDoc](https://godoc.org/gopkg.in/bluesuncorp/validator.v7?status.svg)](https://godoc.org/gopkg.in/bluesuncorp/validator.v7)
5+
[![Build Status](https://semaphoreci.com/api/v1/projects/ec20115f-ef1b-4c7d-9393-cc76aba74eb4/523019/badge.svg)](https://semaphoreci.com/joeybloggs/validator)
6+
[![Coverage Status](https://coveralls.io/repos/bluesuncorp/validator/badge.svg?branch=v8-development&service=github)](https://coveralls.io/github/bluesuncorp/validator?branch=v8-development)
7+
[![GoDoc](https://godoc.org/gopkg.in/bluesuncorp/validator.v8?status.svg)](https://godoc.org/gopkg.in/bluesuncorp/validator.v8)
88

99
Package validator implements value validations for structs and individual fields based on tags.
1010

examples/custom/custom.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"fmt"
77
"reflect"
88

9-
"gopkg.in/bluesuncorp/validator.v7"
9+
"gopkg.in/bluesuncorp/validator.v8"
1010
)
1111

1212
// DbBackedUser User struct
@@ -17,10 +17,7 @@ type DbBackedUser struct {
1717

1818
func main() {
1919

20-
config := validator.Config{
21-
TagName: "validate",
22-
ValidationFuncs: validator.BakedInValidators,
23-
}
20+
config := &validator.Config{TagName: "validate"}
2421

2522
validate := validator.New(config)
2623

@@ -30,7 +27,7 @@ func main() {
3027
x := DbBackedUser{Name: sql.NullString{String: "", Valid: true}, Age: sql.NullInt64{Int64: 0, Valid: false}}
3128
errs := validate.Struct(x)
3229

33-
if len(errs) > 0 {
30+
if errs != nil {
3431
fmt.Printf("Errs:\n%+v\n", errs)
3532
}
3633
}

examples/simple/simple.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
sql "database/sql/driver"
99

10-
"gopkg.in/bluesuncorp/validator.v7"
10+
"gopkg.in/bluesuncorp/validator.v8"
1111
)
1212

1313
// User contains user information
@@ -32,10 +32,7 @@ var validate *validator.Validate
3232

3333
func main() {
3434

35-
config := validator.Config{
36-
TagName: "validate",
37-
ValidationFuncs: validator.BakedInValidators,
38-
}
35+
config := &validator.Config{TagName: "validate"}
3936

4037
validate = validator.New(config)
4138

@@ -67,7 +64,7 @@ func validateStruct() {
6764

6865
fmt.Println(errs) // output: Key: "User.Age" Error:Field validation for "Age" failed on the "lte" tag
6966
// Key: "User.Addresses[0].City" Error:Field validation for "City" failed on the "required" tag
70-
err := errs["User.Addresses[0].City"]
67+
err := errs.(validator.ValidationErrors)["User.Addresses[0].City"]
7168
fmt.Println(err.Field) // output: City
7269
fmt.Println(err.Tag) // output: required
7370
fmt.Println(err.Kind) // output: string
@@ -135,17 +132,10 @@ func ValidateValuerType(field reflect.Value) interface{} {
135132

136133
func main2() {
137134

138-
customTypes := map[reflect.Type]validator.CustomTypeFunc{}
139-
customTypes[reflect.TypeOf((*sql.Valuer)(nil))] = ValidateValuerType
140-
customTypes[reflect.TypeOf(valuer{})] = ValidateValuerType
141-
142-
config := validator.Config{
143-
TagName: "validate",
144-
ValidationFuncs: validator.BakedInValidators,
145-
CustomTypeFuncs: customTypes,
146-
}
135+
config := &validator.Config{TagName: "validate"}
147136

148137
validate2 = validator.New(config)
138+
validate2.RegisterCustomTypeFunc(ValidateValuerType, (*sql.Valuer)(nil), valuer{})
149139

150140
validateCustomFieldType()
151141
}

examples_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ package validator_test
33
import (
44
"fmt"
55

6-
// "gopkg.in/bluesuncorp/validator.v7"
7-
"../validator"
6+
"gopkg.in/bluesuncorp/validator.v8"
87
)
98

109
func ExampleValidate_new() {

0 commit comments

Comments
 (0)