mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 04:22:22 +00:00
Update ch5-04-validator.md
This commit is contained in:
parent
71af00ac37
commit
27b0d2ede9
@ -91,10 +91,13 @@ type RegisterReq struct {
|
||||
Email string `validate:"email"`
|
||||
}
|
||||
|
||||
validate := validator.New()
|
||||
|
||||
func validate(req RegisterReq) error {
|
||||
err := validate.Struct(mystruct)
|
||||
err := validate.Struct(req)
|
||||
if err != nil {
|
||||
doSomething()
|
||||
return err
|
||||
}
|
||||
...
|
||||
}
|
||||
@ -115,7 +118,7 @@ var req = RegisterReq {
|
||||
Email : "alex@abc.com",
|
||||
}
|
||||
|
||||
err := validate.Struct(mystruct)
|
||||
err := validate(req)
|
||||
fmt.Println(err) // Key: 'RegisterReq.PasswordRepeat' Error:Field validation for 'PasswordRepeat' failed on the 'eqfield' tag
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user