Func accepts a variadic number of functions which accept the value of the field and return a string message if the value is invalid. It joins the reasons into one.
(fns ...func(value T) string)
| 62 | // and return a string message if the value is invalid. |
| 63 | // It joins the reasons into one. |
| 64 | func (e *FieldError[T]) Func(fns ...func(value T) string) *FieldError[T] { |
| 65 | for _, fn := range fns { |
| 66 | e.joinReason(fn(e.Value)) |
| 67 | } |
| 68 | |
| 69 | return e |
| 70 | } |
| 71 | |
| 72 | // Join joins the given validation errors into one. |
| 73 | func Join(errs ...errors.ValidationError) error { // note that here we return the standard error type instead of the errors.ValidationError in order to make the error nil instead of ValidationErrors(nil) on empty slice. |