Skip to content
/ errs Public

A package providing application errors and helpers for translating errors to different wire protocols e.g.(http, gRPC).

License

Notifications You must be signed in to change notification settings

actatum/errs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

errs

Go Report Card Build Status codecov Godoc Release

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

Installation

go get github.com/actatum/errs

Usage

Basic

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())
}

HTTP Handler

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)
}

About

A package providing application errors and helpers for translating errors to different wire protocols e.g.(http, gRPC).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages