Skip to content

Commit

Permalink
Merge pull request #72 from rezakhademix/better-method-comments
Browse files Browse the repository at this point in the history
improved: better comments for validation methods
  • Loading branch information
rezakhademix authored Apr 2, 2024
2 parents 6f465db + 8fbadfd commit 70aebb1
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions between.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const (
//
// Example:
//
// govalidator.BetweenInt(21, 1, 10, "age", "age must be between 1 and 10.")
// validator.BetweenInt(21, 1, 10, "age", "age must be between 1 and 10.")
func (v *Validator) BetweenInt(i, min, max int, field, msg string) *Validator {
v.Check(i >= min && i <= max, field, v.msg(Between, msg, field, min, max))

Expand All @@ -22,7 +22,7 @@ func (v *Validator) BetweenInt(i, min, max int, field, msg string) *Validator {
//
// Example:
//
// govalidator.BetweenFloat(3.5, 2.0, 5.0, "height", "height must be between 2.0 and 5.0 meters.")
// validator.BetweenFloat(3.5, 2.0, 5.0, "height", "height must be between 2.0 and 5.0 meters.")
func (v *Validator) BetweenFloat(f, min, max float64, field, msg string) *Validator {
v.Check(f >= min && f <= max, field, v.msg(Between, msg, field, min, max))

Expand Down
2 changes: 1 addition & 1 deletion date.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
//
// Example:
//
// govalidator.Date("2006-01-02", "2024-03-09","birthdate", "birthdate must be a valid date in the format YYYY-MM-DD.")
// validator.Date("2006-01-02", "2024-03-09","birthdate", "birthdate must be a valid date in the format YYYY-MM-DD.")
func (v *Validator) Date(layout, d, field, msg string) *Validator {
_, err := time.Parse(layout, d)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion email.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
//
// Example:
//
// govalidator.Email("john.doe@example.com", "email", "email address is not valid.")
// validator.Email("john.doe@example.com", "email", "email address is not valid.")
func (v *Validator) Email(s, field, msg string) *Validator {
v.RegexMatches(s, EmailRegex, field, v.msg(Email, msg, field))

Expand Down
2 changes: 1 addition & 1 deletion exists.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const (
//
// Example:
//
// govalidator.Exists(42, "users", "id", "user_id", "user with id 42 does not exist.")
// validator.Exists(42, "users", "id", "user_id", "user with id 42 does not exist.")
func (v *Validator) Exists(value any, table, column, field, msg string) *Validator {
v.Check(v.repo.Exists(value, table, column), field, v.msg(Exists, msg, field))

Expand Down
6 changes: 3 additions & 3 deletions len.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
//
// Example:
//
// govalidator.LenString("rez", 5, "username", "username must be 5 characters.")
// validator.LenString("rez", 5, "username", "username must be 5 characters.")
func (v *Validator) LenString(s string, size int, field, msg string) *Validator {
v.Check(len(strings.TrimSpace(s)) == size, field, v.msg(Len, msg, field, size))

Expand All @@ -31,7 +31,7 @@ func (v *Validator) LenString(s string, size int, field, msg string) *Validator
//
// Example:
//
// govalidator.LenInt(12345, 5, "zipcode", "Zip code must be 5 digits long.")
// validator.LenInt(12345, 5, "zipcode", "Zip code must be 5 digits long.")
func (v *Validator) LenInt(i, size int, field, msg string) *Validator {
v.Check(len(strconv.Itoa(i)) == size, field, v.msg(Len, msg, field, size))

Expand All @@ -42,7 +42,7 @@ func (v *Validator) LenInt(i, size int, field, msg string) *Validator {
//
// Example:
//
// govalidator.LenSlice([]int{1, 2, 3, 4, 5}, 5, "numbers", "the list must contain exactly 5 numbers.")
// validator.LenSlice([]int{1, 2, 3, 4, 5}, 5, "numbers", "the list must contain exactly 5 numbers.")
func (v *Validator) LenSlice(s []any, size int, field, msg string) *Validator {
v.Check(len(s) == size, field, v.msg(LenList, msg, field, size))

Expand Down
6 changes: 3 additions & 3 deletions max.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
//
// Example:
//
// govalidator.MaxInt(10, 100, "age", "age must be less than 100.")
// validator.MaxInt(10, 100, "age", "age must be less than 100.")
func (v *Validator) MaxInt(i, max int, field, msg string) *Validator {
v.Check(i <= max, field, v.msg(Max, msg, field, max))

Expand All @@ -28,7 +28,7 @@ func (v *Validator) MaxInt(i, max int, field, msg string) *Validator {
//
// Example:
//
// govalidator.MaxFloat(3.5, 5.0, "height", "height must be less than 5.0 meters.")
// validator.MaxFloat(3.5, 5.0, "height", "height must be less than 5.0 meters.")
func (v *Validator) MaxFloat(f, max float64, field, msg string) *Validator {
v.Check(f <= max, field, v.msg(Max, msg, field, max))

Expand All @@ -39,7 +39,7 @@ func (v *Validator) MaxFloat(f, max float64, field, msg string) *Validator {
//
// Example:
//
// govalidator.MaxString("rey", 5, "name", "name should has less than 5 characters.")
// validator.MaxString("rey", 5, "name", "name should has less than 5 characters.")
func (v *Validator) MaxString(s string, maxLen int, field, msg string) *Validator {
v.Check(len(strings.TrimSpace(s)) <= maxLen, field, v.msg(MaxString, msg, field, maxLen))

Expand Down
6 changes: 3 additions & 3 deletions min.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
//
// Example:
//
// govalidator.MinInt(18, 0, "age", "age must be at least 0.")
// validator.MinInt(18, 0, "age", "age must be at least 0.")
func (v *Validator) MinInt(i, min int, field, msg string) *Validator {
v.Check(i >= min, field, v.msg(Min, msg, field, min))

Expand All @@ -28,7 +28,7 @@ func (v *Validator) MinInt(i, min int, field, msg string) *Validator {
//
// Example:
//
// govalidator.MinFloat(5.0, 0.0, "height", "height must be at least 0.0 meters.")
// validator.MinFloat(5.0, 0.0, "height", "height must be at least 0.0 meters.")
func (v *Validator) MinFloat(f, min float64, field, msg string) *Validator {
v.Check(f >= min, field, v.msg(Min, msg, field, min))

Expand All @@ -39,7 +39,7 @@ func (v *Validator) MinFloat(f, min float64, field, msg string) *Validator {
//
// Example:
//
// govalidator.MinString("rey", 5, "name", "name should has more than 5 characters.")
// validator.MinString("rey", 5, "name", "name should has more than 5 characters.")
func (v *Validator) MinString(s string, minLen int, field, msg string) *Validator {
v.Check(len(strings.TrimSpace(s)) >= minLen, field, v.msg(MinString, msg, field, minLen))

Expand Down
2 changes: 1 addition & 1 deletion notexists.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
//
// Example:
//
// govalidator.NotExists(42, "users", "id", "user_id", "user with id 42 already exists.")
// validator.NotExists(42, "users", "id", "user_id", "user with id 42 already exists.")
func (v *Validator) NotExists(value any, table, column, field, msg string) *Validator {
v.Check(!v.repo.Exists(value, table, column), field, v.msg(NotExists, msg, field))

Expand Down
2 changes: 1 addition & 1 deletion regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
//
// Example:
//
// govalidator.RegexMatches("example123", "[a-z]+[0-9]+", "input", "input must contain letters followed by numbers.")
// validator.RegexMatches("example123", "[a-z]+[0-9]+", "input", "input must contain letters followed by numbers.")
func (v *Validator) RegexMatches(s string, pattern string, field, msg string) *Validator {
r := regexp.MustCompile(pattern)

Expand Down
8 changes: 4 additions & 4 deletions required.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
//
// Example:
//
// govalidator.RequiredString("hello", "username", "username is required.")
// validator.RequiredString("hello", "username", "username is required.")
func (v *Validator) RequiredString(s, field string, msg string) *Validator {
v.Check(strings.TrimSpace(s) != "", field, v.msg(Required, msg, field))

Expand All @@ -24,7 +24,7 @@ func (v *Validator) RequiredString(s, field string, msg string) *Validator {
//
// Example:
//
// govalidator.RequiredInt(42, "age", "age is required.")
// validator.RequiredInt(42, "age", "age is required.")
func (v *Validator) RequiredInt(i int, field string, msg string) *Validator {
v.Check(i != 0, field, v.msg(Required, msg, field))

Expand All @@ -35,7 +35,7 @@ func (v *Validator) RequiredInt(i int, field string, msg string) *Validator {
//
// Example:
//
// govalidator.RequiredSlice([]string{"apple", "banana", "orange"}, "fruits", "at least one fruit must be provided.")
// validator.RequiredSlice([]string{"apple", "banana", "orange"}, "fruits", "at least one fruit must be provided.")
func (v *Validator) RequiredSlice(s []any, field string, msg string) *Validator {
v.Check(len(s) > 0, field, v.msg(Required, msg, field))

Expand All @@ -46,7 +46,7 @@ func (v *Validator) RequiredSlice(s []any, field string, msg string) *Validator
//
// Example:
//
// govalidator.RequiredFloat(3.5, "weight", "weight is required.")
// validator.RequiredFloat(3.5, "weight", "weight is required.")
func (v *Validator) RequiredFloat(f float64, field string, msg string) *Validator {
v.Check(f != 0.0, field, v.msg(Required, msg, field))

Expand Down
2 changes: 1 addition & 1 deletion uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
//
// Example:
//
// govalidator.UUID("f47ac10b-58cc-4372-a567-0e02b2c3d479", "uuid", "Invalid UUID format.")
// validator.UUID("f47ac10b-58cc-4372-a567-0e02b2c3d479", "uuid", "Invalid UUID format.")
func (v *Validator) UUID(u, field, msg string) *Validator {
_, err := uuid.Parse(u)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions when.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ package govalidator
//
// Example:
//
// govalidator.When(len(username) > 0, func() {
// govalidator.RequiredString(username, "username", "username is required.")
// validator.When(len(username) > 0, func() {
// validator.RequiredString(username, "username", "username is required.")
// })
func (v *Validator) When(condition bool, f func()) *Validator {
if condition {
Expand Down

0 comments on commit 70aebb1

Please sign in to comment.