/erkhttp

HTTP Status codes for Erk error kinds

Primary LanguageGoMIT LicenseMIT

erkhttp

Allows erk error kinds to embed HTTP Statuses.

GoDoc go.dev reference

Install

$ github.com/JosiahWitt/erkhttp

Usage

Embed HTTP Statuses in erk errors:

type ErkItemNotFound {
  erk.DefaultKind
  erkhttp.StatusNotFound
}

Fetch the HTTP Status using erkhttp.GetHTTPStatus:

var ErrItemNotFound = erk.New(ErkItemNotFound{}, "item with key '{{.key}}' was not found")

func main() {
  fmt.Println(erkhttp.GetHTTPStatus(ErrItemNotFound)) // Prints 404, true
}