clair/vendor/github.com/coreos/pkg/multierror/multierror.go
2016-06-07 10:08:50 +02:00

33 lines
637 B
Go

// Package multierror wraps a slice of errors and implements the error interface.
// This can be used to collect a bunch of errors (such as during form validation)
// and then return them all together as a single error. To see usage examples
// refer to the unit tests.
package multierror
import (
"fmt"
"strings"
)
type Error []error
func (me Error) Error() string {
if me == nil {
return ""
}
strs := make([]string, len(me))
for i, err := range me {
strs[i] = fmt.Sprintf("[%d] %v", i, err)
}
return strings.Join(strs, " ")
}
func (me Error) AsError() error {
if len([]error(me)) <= 0 {
return nil
}
return me
}