errs is a package providing application errors for go services.
The package provides error codes that are human readable and map well to transport error codes or status'. It also provides a constructor for new errors and ability to parse the code and message from a go error interface if the packages provided Error type is the underlying implementation. This package also provides some smaller packages for interacting with different transport protocols and translating errors to the expected result in each protocol e.g.(http, gRPC, connect).
This package supports the two latest go versions
go get github.com/actatum/errs
package main
import (
"fmt"
"github.com/actatum/errs"
)
func main() {
thingID := "1"
err := errs.Errorf(errs.NotFound, "no thing with id: %s", thingID)
fmt.Println(err.Error())
}
package handlers
import (
"log"
"net/http"
"github.com/actatum/errs/httperr"
)
type request struct {
X string `json:"x"`
}
func h(w http.ResponseWriter, r *http.Request) {
var req request
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
httperr.RenderError(err)
return
}
log.Printf("request: %v\n", req)
}