refactor: openpitrix module
Signed-off-by: hongming <talonwan@yunify.com>
This commit is contained in:
28
vendor/github.com/koding/multiconfig/multivalidator.go
generated
vendored
Normal file
28
vendor/github.com/koding/multiconfig/multivalidator.go
generated
vendored
Normal file
@@ -0,0 +1,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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user