add all validator, simplify error messages

This commit is contained in:
Aneurin Barker Snook
2023-10-07 13:42:17 +01:00
parent c2efe16dc0
commit c74486d122
8 changed files with 98 additions and 19 deletions
+14
View File
@@ -0,0 +1,14 @@
package validate
// All validates a value using a sequence of validation functions.
// If any validation function returns an error, the sequence stops and the error is returned.
func All[T any](fs ...func(T) error) func(T) error {
return func(value T) error {
for _, f := range fs {
if err := f(value); err != nil {
return err
}
}
return nil
}
}