interface.go 992 B

1234567891011121314151617181920212223242526272829
  1. package valid
  2. import (
  3. "context"
  4. )
  5. // Validatable is the interface indicating the type implementing it supports data validation.
  6. type Validatable interface {
  7. // Validate validates the data and returns an error if validation fails.
  8. Validate() error
  9. }
  10. // ValidatableWithContext is the interface indicating the type implementing it supports context-aware data validation.
  11. type ValidatableWithContext interface {
  12. // ValidateWithContext validates the data with the given context and returns an error if validation fails.
  13. ValidateWithContext(ctx context.Context) error
  14. }
  15. // Rule represents a validation rule.
  16. type Rule interface {
  17. // Validate validates a value and returns a value if validation fails.
  18. Validate(value interface{}) error
  19. }
  20. // RuleWithContext represents a context-aware validation rule.
  21. type RuleWithContext interface {
  22. // ValidateWithContext validates a value and returns a value if validation fails.
  23. ValidateWithContext(ctx context.Context, value interface{}) error
  24. }