rule.go 576 B

12345678910111213141516171819202122232425
  1. package valid
  2. var (
  3. // ErrNilOrNotEmpty is the error that returns when a value is not nil and is empty.
  4. ErrNilOrNotEmpty = NewError("validation_nil_or_not_empty_required", "cannot be blank")
  5. )
  6. var (
  7. // Skip is a special validation rule that indicates all rules following it should be skipped.
  8. Skip = skipRule{skip: true}
  9. )
  10. type skipRule struct {
  11. skip bool
  12. }
  13. func (r skipRule) Validate(interface{}) error {
  14. return nil
  15. }
  16. // When determines if all rules following it should be skipped.
  17. func (r skipRule) When(condition bool) skipRule {
  18. r.skip = condition
  19. return r
  20. }