Skip to content

JosiahWitt/erkhttp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
}