@cryptotaxi247 / kubo / commits / 55d1e794c

multierr

Juan Batiz-Benet committed Dec 14, 2014 at 11:35 UTC 55d1e794c75406cce6bcfc8913de61c4368b9249
1 file changed +30
util/multierr/multierr.go new
+30
@@ -0,0 +1,30 @@
1 +package multierr
2 +
3 +import (
4 + "fmt"
5 +)
6 +
7 +// Error contains a set of errors. Used to return multiple errors, as in listen.
8 +type Error struct {
9 + Errors []error
10 +}
11 +
12 +func (e *Error) Error() string {
13 + if e == nil {
14 + return "<nil error>"
15 + }
16 + var out string
17 + for i, v := range e.Errors {
18 + if v != nil {
19 + out += fmt.Sprintf("%d: %s\n", i, v)
20 + }
21 + }
22 + return out
23 +}
24 +
25 +func New(errs ...error) *Error {
26 + if len(errs) == 0 {
27 + return nil
28 + }
29 + return &Error{errs}
30 +}