recovery/recovery.go
func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	defer func() {
		if err := recover(); err != nil {
			debugMsg := fmt.Sprintf(
				"%s\n\n%#v\n\n%#v",
				debug.Stack(),
				r.URL,
				r.Header,
			)
			if h.label != "" {
				debugMsg = h.label + "\n\n" + debugMsg
			}
			h.logf("http recovery handler: %s %s: %s\n%s", r.Method, r.URL.String(), err, debugMsg)

			if h.notifier != nil {
				go func() {
					defer func() {
						if err := recover(); err != nil {
							h.logf("http recovery handler: notify panic: %v", err)
						}
					}()

					if err := h.notifier.Notify(
						fmt.Sprint(
							"Panic ",
							r.Method,
							" ",
							r.URL.String(),
							": ", err,
						),
						debugMsg,
					); err != nil {
						h.logf("http recovery handler: notify: %v", err)
					}
				}()
			}

			if h.panicResponseHandler != nil {
				h.panicResponseHandler.ServeHTTP(w, r)
				return
			}

			if h.panicContentType != "" {
				w.Header().Set("Content-Type", h.panicContentType)
			}
			w.WriteHeader(http.StatusInternalServerError)
			if h.panicBody != "" {
				fmt.Fprintln(w, h.panicBody)
			}
		}
	}()

	h.handler.ServeHTTP(w, r)
}
func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	defer func() {
		if err := recover(); err != nil {
			debugMsg := fmt.Sprintf(
				"%s\n\n%#v\n\n%#v",
				debug.Stack(),
				r.URL,
				r.Header,
			)
			if h.label != "" {
				debugMsg = h.label + "\n\n" + debugMsg
			}
			h.logf("http recovery handler: %s %s: %s\n%s", r.Method, r.URL.String(), err, debugMsg)

			if h.notifier != nil {
				go func() {
					defer func() {
						if err := recover(); err != nil {
							h.logf("http recovery handler: notify panic: %v", err)
						}
					}()

					if err := h.notifier.Notify(
						fmt.Sprint(
							"Panic ",
							r.Method,
							" ",
							r.URL.String(),
							": ", err,
						),
						debugMsg,
					); err != nil {
						h.logf("http recovery handler: notify: %v", err)
					}
				}()
			}

			if h.panicResponseHandler != nil {
				h.panicResponseHandler.ServeHTTP(w, r)
				return
			}

			if h.panicContentType != "" {
				w.Header().Set("Content-Type", h.panicContentType)
			}
			w.WriteHeader(http.StatusInternalServerError)
			if h.panicBody != "" {
				fmt.Fprintln(w, h.panicBody)
			}
		}
	}()

	h.handler.ServeHTTP(w, r)
}
// ServeHTTP implements http.Handler interface.