certman/middleware/panic.go

27 lines
492 B
Go
Raw Permalink Normal View History

2018-04-22 16:55:50 +02:00
package middleware
import (
"log"
"net/http"
"runtime/debug"
"git.klink.asia/paul/certman/handlers"
)
// Recoverer Listens for panic() calls and logs the stacktrace.
func Recoverer(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
defer func() {
if rvr := recover(); rvr != nil {
log.Println(rvr)
log.Println(string(debug.Stack()))
handlers.ErrorHandler(w, r)
}
}()
next.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}