errlist

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2019 License: MIT Imports: 1 Imported by: 4

README

errlist

Group a few errors in one error.

Example

type query struct {
	url.Values
	errs []error
}

func (q *query) Error() error { return errlist.Error(q.errs) }

func (q *query) Int(name string) int {
	if value := q.Get(name); value != "" {
		i, err := strconv.Atoi(value)
		q.errs = errlist.Append(q.errs, err)
		return i
	}
	return 0
}

func handler(r *http.Request, w http.ResponseWriter) {
	q := query{Values: r.URL.Query()}
	a := q.Int("a")
	b := q.Int("b")
	c := q.Int("c")

	if err := q.Err(); err != nil {
		// Here we return a error combined of the errors of parsing a, b, c params.
		http.Error(w, err, http.StatusBadRequest)
		return
	}

	// ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(errs []error, err ...error) []error

Append appends a error(s) to the list of errors. If the appending error(s) is nil then it will be ignored.

func Error

func Error(errs []error) error

Error returns one new error built from the list of errors. If nil or an empty list is given then nil (no error) will be returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL