Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing typo at test file and add README description #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ db.Create(&User{}).GetErrors() // => []error{"age need to be 18+", "name can't b

## [Govalidator](https://github.com/asaskevich/govalidator) integration

Qor [Validations](https://github.com/qor/validations) supports [govalidator](https://github.com/asaskevich/govalidator), so you could add a tag into your struct for some common *validations*, such as *check required*, *numeric*, *length*, etc.
Qor [Validations](https://github.com/qor/validations) supports [govalidator](https://github.com/asaskevich/govalidator), so you could add a tag into your struct for some common *validations*, such as *check required*, *numeric*, *length*, etc.
*Use "," for separation between validations*

```
type User struct {
gorm.Model
Name string `valid:"required"`
Password string `valid:"length(6|20)"`
SecurePassword string `valid:"numeric"`
Email string `valid:"email"`
Name string `valid:"required"`
Password string `valid:"length(6|20)"`
SecurePassword string `valid:"numeric"`
Email string `valid:"email"`
Username string `valid:"required,length(6|20)"`
}
```

Expand Down
6 changes: 3 additions & 3 deletions validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type User struct {
Name string `valid:"required"`
Password string `valid:"length(6|20)"`
SecurePassword string `valid:"numeric"`
Email string `valid:"email,uniqEmail~Email already be token"`
Email string `valid:"email,uniqEmail~Email already be taken"`
CompanyID int
Company Company
CreditCard CreditCard
Expand Down Expand Up @@ -127,8 +127,8 @@ func TestGoValidation(t *testing.T) {
user = User{Name: "A", Password: "123123", Email: "[email protected]"}
result = db.Save(&user)
user = User{Name: "B", Password: "123123", Email: "[email protected]"}
if result := db.Save(&user); result.Error.Error() != "Email already be token" {
t.Errorf("Should get email alredy be token error")
if result := db.Save(&user); result.Error.Error() != "Email already be taken" {
t.Errorf("Should get email alredy be taken error")
}
}

Expand Down