From 8c39884e987f1c0f195e37387822df33ad8a9f18 Mon Sep 17 00:00:00 2001 From: Josiah Witt Date: Sun, 23 Feb 2020 15:31:10 -0500 Subject: [PATCH] Add README --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..f75fece --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# erkhttp + +Allows [`erk`](https://github.com/JosiahWitt/erk) error kinds to embed HTTP Statuses. + +[![GoDoc](https://godoc.org/github.com/JosiahWitt/erkhttp?status.svg)](https://godoc.org/github.com/JosiahWitt/erkhttp) +[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/JosiahWitt/erkhttp) + + +## Install +```bash +$ github.com/JosiahWitt/erkhttp +``` + + +## Usage +Embed HTTP Statuses in erk errors: + +```go +type ErkItemNotFound { + erk.DefaultKind + erkhttp.StatusNotFound +} +``` + +Fetch the HTTP Status using [`erkhttp.GetHTTPStatus`](https://pkg.go.dev/github.com/JosiahWitt/erkhttp?tab=doc#GetHTTPStatus): +```go +var ErrItemNotFound = erk.New(ErkItemNotFound{}, "item with key '{{.key}}' was not found") + +func main() { + fmt.Println(erkhttp.GetHTTPStatus(ErrItemNotFound)) // Prints 404, true +} +```