Another possible extension of that design is using error types for HTTP codes. Something like:
type HTTPError struct {
Err error
Code int
}
And then, with a couple of wrappers like this: func errorNotFound(err error) (wrapped error) {
return &HTTPError{
Err: err,
Code: http.StatusNotFound,
}
}
you could do something like this: return errorNotFound(err)
or this: return errorInternal(err) // 500 Internal Server Error