You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
572 B
42 lines
572 B
package multierror
|
|
|
|
func Join(errs ...error) error {
|
|
n := 0
|
|
for _, err := range errs {
|
|
if err != nil {
|
|
n++
|
|
}
|
|
}
|
|
if n == 0 {
|
|
return nil
|
|
}
|
|
e := &joinError{
|
|
errs: make([]error, 0, n),
|
|
}
|
|
for _, err := range errs {
|
|
if err != nil {
|
|
e.errs = append(e.errs, err)
|
|
}
|
|
}
|
|
return e
|
|
}
|
|
|
|
type joinError struct {
|
|
errs []error
|
|
}
|
|
|
|
func (e *joinError) Error() string {
|
|
var b []byte
|
|
for i, err := range e.errs {
|
|
if i > 0 {
|
|
b = append(b, '\n')
|
|
}
|
|
b = append(b, err.Error()...)
|
|
}
|
|
return string(b)
|
|
}
|
|
|
|
func (e *joinError) Unwrap() []error {
|
|
return e.errs
|
|
}
|