File size: 547 Bytes
6380833 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | package models
import "errors"
type Validator interface {
// Validate returns an error if the instance of the Validator is invalid.
Validate() error
}
type ValidatorFunc[T any] func(T) error
type CustomValidator[T any] interface {
ValidateWith(...ValidatorFunc[T]) error
}
func Validate[T any](v T, validators ...ValidatorFunc[T]) error {
var errs []error
for _, validator := range validators {
if err := validator(v); err != nil {
errs = append(errs, err)
}
}
return NewNillableGenericValidationError(errors.Join(errs...))
}
|