func (mw *RecoverMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc {
	if mw.Logger == nil {
		mw.Logger = log.New(os.Stderr, "", 0)
	}
	return func(w ResponseWriter, r *Request) {
		defer func() {
			if reco := recover(); reco != nil {
				trace := debug.Stack()
				message := fmt.Sprintf("%s\n%s", reco, trace)
				mw.logError(message)
				if mw.EnableResponseStackTrace {
					Error(w, message, http.StatusInternalServerError)
				} else {
					Error(w, "Internal Server Error", http.StatusInternalServerError)
				}
			}
		}()
		h(w, r)
	}
}
MiddlewareFunc makes RecoverMiddleware implement the Middleware interface.
package rest
import (
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"os"
	"runtime/debug"
)
type RecoverMiddleware struct {
	Logger *log.Logger
	EnableLogAsJson bool
	EnableResponseStackTrace bool
}