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

Add translation feature. #91

Merged
merged 12 commits into from
Jan 30, 2020
Prev Previous commit
Next Next commit
--amend
Refactor Error definition in rules.
  • Loading branch information
mehran-prs committed Jan 27, 2020
commit 329f7b1d9842183c6b1b3b59b5d655d0401cbf38
2 changes: 1 addition & 1 deletion is/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

var (
// ErrValidationIsEmail is the error that returns in case of an invalid email.
// ErrEmail is the error that returns in case of an invalid email.
ErrEmail = validation.NewError("validation_is_email", "must be a valid email address")
// ErrURL is the error that returns in case of an invalid URL.
ErrURL = validation.NewError("validation_is_url", "must be a valid URL")
Expand Down
14 changes: 7 additions & 7 deletions required.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package validation
var (
// ErrRequired is the error that returns when a value is required.
ErrRequired = NewError("validation_required", "cannot be blank")
// ErrNotNilRequired is the error that returns when a value is not nil and is empty.
// ErrNilOrNotEmpty is the error that returns when a value is not nil and is empty.
ErrNilOrNotEmpty = NewError("validation_nil_or_not_empty_required", "cannot be blank")
)

Expand All @@ -30,19 +30,19 @@ type requiredRule struct {
}

// Validate checks if the given value is valid or not.
func (v requiredRule) Validate(value interface{}) error {
func (r requiredRule) Validate(value interface{}) error {
value, isNil := Indirect(value)
if v.skipNil && !isNil && IsEmpty(value) || !v.skipNil && (isNil || IsEmpty(value)) {
return v.err
if r.skipNil && !isNil && IsEmpty(value) || !r.skipNil && (isNil || IsEmpty(value)) {
return r.err
}
return nil
}

// Error sets the error message for the rule.
func (v requiredRule) Error(message string) requiredRule {
v.err.SetMessage(message)
func (r requiredRule) Error(message string) requiredRule {
r.err.SetMessage(message)

return v
return r
}

// ErrorObject sets the error struct for the rule.
Expand Down