forked from koding/multiconfig
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultivalidator.go
More file actions
28 lines (23 loc) · 809 Bytes
/
Copy pathmultivalidator.go
File metadata and controls
28 lines (23 loc) · 809 Bytes
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
28
package multiconfig
type multiValidator []Validator
// MultiValidator accepts variadic validators and satisfies Validator interface.
func MultiValidator(validators ...Validator) Validator {
return multiValidator(validators)
}
// Validate tries to validate given struct with all the validators. If it doesn't
// have any Validator it will simply skip the validation step. If any of the
// given validators return err, it will stop validating and return it.
func (d multiValidator) Validate(s interface{}) error {
for _, validator := range d {
if err := validator.Validate(s); err != nil {
return err
}
}
return nil
}
// MustValidate validates the struct, it panics if gets any error
func (d multiValidator) MustValidate(s interface{}) {
if err := d.Validate(s); err != nil {
panic(err)
}
}