Copyright 2022 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. Join returns an error that wraps the given errors. Any nil error values are discarded. Join returns nil if errs contains no non-nil values. The error
(errs ...error)
| 11 | // by calling the Error method of each element of errs, with a newline |
| 12 | // between each string. |
| 13 | func Join(errs ...error) error { |
| 14 | n := 0 |
| 15 | for _, err := range errs { |
| 16 | if err != nil { |
| 17 | n++ |
| 18 | } |
| 19 | } |
| 20 | if n == 0 { |
| 21 | return nil |
| 22 | } |
| 23 | e := &joinError{ |
| 24 | errs: make([]error, 0, n), |
| 25 | } |
| 26 | for _, err := range errs { |
| 27 | if err != nil { |
| 28 | e.errs = append(e.errs, err) |
| 29 | } |
| 30 | } |
| 31 | return e |
| 32 | } |
| 33 | |
| 34 | type joinError struct { |
| 35 | errs []error |