1234567891011121314151617181920212223 |
- package validation
- // ValidationError represents a single validation error
- type ValidationError struct {
- Field string `json:"field"`
- Message string `json:"message"`
- }
- // Validator defines the interface for request validation
- type Validator interface {
- Validate() []ValidationError
- }
- // Validate validates a struct that implements the Validator interface
- func Validate(v interface{}) []ValidationError {
- if validator, ok := v.(Validator); ok {
- return validator.Validate()
- }
- return []ValidationError{{
- Field: "request",
- Message: "request type does not implement Validator interface",
- }}
- }
|