Skip to content

Commit

Permalink
Merge pull request #124 from bluesuncorp/v6-development
Browse files Browse the repository at this point in the history
Slit out assertion funcs. & add single field validation example
  • Loading branch information
Dean Karn authored and Dean Karn committed Jul 27, 2015
2 parents b9cdaa4 + f462515 commit 54927e9
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 145 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Usage and documentation

Please see http://godoc.org/gopkg.in/bluesuncorp/validator.v6 for detailed usage docs.

##### Example:
##### Examples:
```go
package main

Expand Down Expand Up @@ -73,6 +73,12 @@ func main() {

validate = validator.New(config)

validateStruct()
validateField()
}

func validateStruct() {

address := &Address{
Street: "Eavesdown Docks",
Planet: "Persphone",
Expand Down Expand Up @@ -109,6 +115,19 @@ func main() {

// save user to database
}

func validateField() {
myEmail := "joeybloggs.gmail.com"

errs := validate.Field(myEmail, "required,email")

if errs != nil {
fmt.Println(errs) // output: Key: "" Error:Field validation for "" failed on the "email" tag
return
}

// email ok, move on
}
```

Benchmarks
Expand Down
19 changes: 19 additions & 0 deletions examples/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func main() {

validate = validator.New(config)

validateStruct()
validateField()
}

func validateStruct() {

address := &Address{
Street: "Eavesdown Docks",
Planet: "Persphone",
Expand Down Expand Up @@ -71,3 +77,16 @@ func main() {

// save user to database
}

func validateField() {
myEmail := "joeybloggs.gmail.com"

errs := validate.Field(myEmail, "required,email")

if errs != nil {
fmt.Println(errs) // output: Key: "" Error:Field validation for "" failed on the "email" tag
return
}

// email ok, move on
}
Loading

0 comments on commit 54927e9

Please sign in to comment.