err = fn1(...)
if err != nil {
// handle error somehow
}
err = fn2(...)
if err != nil {
// handle error somehow
}
...
a lot of times. This is especially annoying if you want to handle all errors the same way (e.g. return the first error).
queue
provides a way to call functions in a queue while
collecting the errors via a predefined or custom error handler. The
predefined handler returns on the first error and custom error handlers
might be used to catch/handle some/all kinds of errors while keeping the
queue running.
Example:
// create a new queue with the default error handler err := queue.New(). // get the name from the map Add(get, "Name", m). // set the name in the struct Add(p.SetName, queue.PIPE). // get the age from the map Add(get, "Age", m). // convert the age to int Add(strconv.Atoi, queue.PIPE). // set the age in the struct Add(p.SetAge, queue.PIPE). // inspect the struct Add(fmt.Printf, "SUCCESS %#v\n\n", p). // run the whole queue Run()
or with the more compact github.com/go-on/queue/q