Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
guiferpa authored Feb 28, 2020
1 parent 208cbf4 commit 6fd8753
Showing 1 changed file with 3 additions and 47 deletions.
50 changes: 3 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,50 +43,6 @@ func main() {

### Kinds of validation

### Deep validation

```go
package main

import (
"log"

"github.com/guiferpa/gody"
"github.com/guiferpa/gody/rule"
)

type Price struct {
Currency string `json:"currency" validate:"enum=BRL,EUR,USD"`
Value int `json:"value" validate:"min=10"`
}

type ItemProduct struct {
Amount int `json:"amount" validate:"min=1"`

// validate tag's necessary for validation works if not setted it'll be ignored
Price Price `json:"price" validate:"required=true"`
}

func main() {
ip := ItemProduct{Amount: 10, Price: Price{"BYN", 10000}}

if valid, err := gody.Validate(ip, nil); err != nil {
if !valid {
log.Println("product from cart didn't validate because of", err)
return
}

switch err.(type) {
case *rule.ErrRequired:
log.Println("required error:", err)
break

case *rule.ErrEnum:
log.Println("enum error:", err)
break
}
}
}
```

> You can access more [examples](https://github.com/guiferpa/gody/blob/master/example/validate.go)
- [Simple](https://github.com/guiferpa/gody/blob/master/example/validate.go#L11-L29)
- [Deep](https://github.com/guiferpa/gody/blob/master/example/validate.go#L84-L115)
- [Custom](https://github.com/guiferpa/gody/blob/master/example/validate.go#L31-L82)

0 comments on commit 6fd8753

Please sign in to comment.