Skip to content

Commit

Permalink
Merge pull request #171 from bluesuncorp/v8-development
Browse files Browse the repository at this point in the history
V8 development
  • Loading branch information
deankarn committed Sep 3, 2015
2 parents 40bd6a0 + 0f4bcfc commit 1a791b5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
9 changes: 3 additions & 6 deletions examples/custom/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"reflect"

"gopkg.in/bluesuncorp/validator.v7"
"gopkg.in/bluesuncorp/validator.v8"
)

// DbBackedUser User struct
Expand All @@ -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)

Expand All @@ -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)
}
}
Expand Down
20 changes: 5 additions & 15 deletions examples/simple/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

sql "database/sql/driver"

"gopkg.in/bluesuncorp/validator.v7"
"gopkg.in/bluesuncorp/validator.v8"
)

// User contains user information
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down
3 changes: 1 addition & 2 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package validator_test
import (
"fmt"

// "gopkg.in/bluesuncorp/validator.v7"
"../validator"
"gopkg.in/bluesuncorp/validator.v8"
)

func ExampleValidate_new() {
Expand Down

0 comments on commit 1a791b5

Please sign in to comment.