finalizing logging and multierror
This commit is contained in:
58
multierr/doc.go
Normal file
58
multierr/doc.go
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
Package multierr provides a simple way of handling multiple errors and consolidating them into a single error.
|
||||
|
||||
Example:
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
`r00t2.io/goutils/multierr`
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
var err error
|
||||
var errs []error
|
||||
|
||||
errs = make([]error, 0)
|
||||
|
||||
for _, i := range someSlice {
|
||||
go func() {
|
||||
if err = i.DoSomething(); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
if errs != nil && len(errs) != 0 {
|
||||
// err now contains multiple errors presented as a single error.
|
||||
err = multierr.NewErrors(errs...)
|
||||
}
|
||||
}
|
||||
|
||||
MultiError also has a shorthand, making the above much less verbose:
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
`r00t2.io/goutils/multierr`
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
var err error
|
||||
var multierror *multierr.MultiError = multierr.NewMultiError(nil)
|
||||
|
||||
for _, i := range someSlice {
|
||||
go func() {
|
||||
if err = i.DoSomething(); err != nil {
|
||||
multierror.AddError(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
// multierror now contains any/all errors above.
|
||||
}
|
||||
|
||||
In the above, the multierror assignment can still be used as an error.
|
||||
*/
|
||||
package multierr
|
||||
Reference in New Issue
Block a user