iris/_examples/convert-handlers/real-usecase-raven/wrapping-the-router/main.go
Gerasimos (Makis) Maropoulos 3945fa68d1 obey the vote of @1370 (77-111 at this point) - add import suffix on iris repository
We have to do the same on iris-contrib/examples, iris-contrib/middleware and e.t.c.


Former-commit-id: 0860688158f374bc137bc934b81b26dcd0e10964
2019-10-25 01:27:02 +03:00

46 lines
1.1 KiB
Go

package main
import (
"errors"
"fmt"
"net/http"
"runtime/debug"
"github.com/kataras/iris/v12"
"github.com/getsentry/raven-go"
)
// https://docs.sentry.io/clients/go/integrations/http/
func init() {
raven.SetDSN("https://<key>:<secret>@sentry.io/<project>")
}
func main() {
app := iris.New()
app.Get("/", func(ctx iris.Context) {
ctx.Writef("Hi")
})
// Example for WrapRouter is already here:
// https://github.com/kataras/iris/blob/master/_examples/routing/custom-wrapper/main.go#L53
app.WrapRouter(func(w http.ResponseWriter, r *http.Request, irisRouter http.HandlerFunc) {
// Exactly the same source code:
// https://github.com/getsentry/raven-go/blob/379f8d0a68ca237cf8893a1cdfd4f574125e2c51/http.go#L70
defer func() {
if rval := recover(); rval != nil {
debug.PrintStack()
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)
w.WriteHeader(http.StatusInternalServerError)
}
}()
irisRouter(w, r)
})
app.Run(iris.Addr(":8080"))
}