From 9cd1348d797df4d3f887e9193a8dbad065eda78b Mon Sep 17 00:00:00 2001 From: Muhammad Hendry Date: Wed, 2 Sep 2020 11:20:37 +0700 Subject: [PATCH] fixing typo and add README description --- README.md | 12 +++++++----- validation_test.go | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 75d22a9..831c3d9 100644 --- a/README.md +++ b/README.md @@ -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)"` } ``` diff --git a/validation_test.go b/validation_test.go index 8b05e3d..c29b3dd 100644 --- a/validation_test.go +++ b/validation_test.go @@ -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 @@ -127,8 +127,8 @@ func TestGoValidation(t *testing.T) { user = User{Name: "A", Password: "123123", Email: "a@gmail.com"} result = db.Save(&user) user = User{Name: "B", Password: "123123", Email: "a@gmail.com"} - 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") } }