github.com/blend/go-sdk@v1.20220411.3/validate/all.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package validate 9 10 // All returns a validator that returns all non-nil validation errors from a given 11 // set of validators. 12 func All(validators ...Validator) Validator { 13 return func() error { 14 var output []error 15 var err error 16 for _, validator := range validators { 17 if err = validator(); err != nil { 18 if errs, hasMany := err.(ValidationErrors); hasMany { 19 output = append(output, errs...) 20 } else { 21 output = append(output, err) 22 } 23 } 24 } 25 if len(output) > 0 { 26 return ValidationErrors(output) 27 } 28 return nil 29 } 30 }