Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (47 sloc) 1.7 KB
package main
import (
// At this example you will see how to convert any net/http middleware
// that has the form of `(HandlerFunc) HandlerFunc`.
// If the `raven.RecoveryHandler` had the form of
// `(http.HandlerFunc)` or `(http.HandlerFunc, next http.HandlerFunc)`
// you could just use the `irisMiddleware := iris.FromStd(nativeHandler)`
// but it doesn't, however as you already know Iris can work with net/http directly
// because of the `ctx.ResponseWriter()` and `ctx.Request()` are the original
// http.ResponseWriter and *http.Request.
// (this one is a big advantage, as a result you can use Iris for ever :)).
// The source code of the native middleware does not change at all.
// The only addition is the Line 18 and Line 39 (instead of handler(w,r))
// and you have a new iris middleware ready to use!
func irisRavenMiddleware(ctx iris.Context) {
w, r := ctx.ResponseWriter(), ctx.Request()
defer func() {
if rval := recover(); rval != nil {
rvalStr := fmt.Sprint(rval)
packet := raven.NewPacket(rvalStr, raven.NewException(errors.New(rvalStr), raven.NewStacktrace(2, 3, nil)), raven.NewHttp(r))
raven.Capture(packet, nil)
func init() {
func main() {
app := iris.New()
app.Get("/", func(ctx iris.Context) {
You can’t perform that action at this time.