Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dre1080/recovr
:collision: Go HTTP middleware that catches any panics and serves a proper error response.
https://github.com/dre1080/recovr
Last synced: about 2 months ago
JSON representation
:collision: Go HTTP middleware that catches any panics and serves a proper error response.
- Host: GitHub
- URL: https://github.com/dre1080/recovr
- Owner: dre1080
- License: mit
- Created: 2015-09-29T17:50:26.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-03-08T15:56:58.000Z (almost 3 years ago)
- Last Synced: 2024-06-18T18:48:06.798Z (7 months ago)
- Language: Go
- Homepage:
- Size: 508 KB
- Stars: 133
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# recovr
[![godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://pkg.go.dev/github.com/dre1080/recovr)
Recovr is a HTTP middleware that catches any panics and serves a proper error response.
Works with all frameworks that support native http handler (eg. [Echo](https://github.com/labstack/echo), [Goji](https://github.com/zenazn/goji), etc.).
![HTML](./images/html.jpg)
## Installation
```
$ go get github.com/dre1080/recovr
```## Usage
```go
package mainimport (
"net/http""github.com/dre1080/recovr"
)var myPanicHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
panic("you should not have a handler that just panics ;)")
})func main() {
recovery := recovr.New()
app := recovery(myPanicHandler)
http.ListenAndServe("0.0.0.0:3000", app)
}
```## Examples
### Echo Example
```go
import "github.com/labstack/echo/v4"func main() {
e := echo.New()
e.Use(echo.WrapMiddleware(recovr.New()))
e.Logger.Fatal(e.Start(":1323"))
}
```### Goji Example
```go
import "github.com/zenazn/goji"func main() {
goji.Use(recovr.New())
goji.Serve()
}
```## Screenshots
- **Logger**
![Logger](./images/logger.jpg)
- **JSON**
![JSON](./images/json.jpg)
- **HTML**
![HTML](./images/html.jpg)