rm unused middleware/recover

This commit is contained in:
perennial
2024-10-21 23:03:17 +11:00
parent 125678f6e3
commit 01df022038
2 changed files with 2 additions and 30 deletions
+2 -2
View File
@@ -5,8 +5,8 @@ incoming HTTP requests and produce appropriate responses.
The package includes middleware for security headers (SetPrivacyHeaders), error catching
and handling (CatchError, HandleError), rate limiting (IPRateLimiter, RateLimitRequest), logging (LogRequest),
panic recovery (RecoverFromPanic), and user context injection (ProvideUserContext). These
middlewares can be applied to routes to add cross-cutting functionality across multiple endpoints.
and user context injection (ProvideUserContext). These middlewares can be applied to routes to add cross-cutting
functionality across multiple endpoints.
Route definitions are centralized in the DefineRoutes function, which sets up all paths
and their corresponding handlers using the gorilla/mux router.
-28
View File
@@ -1,28 +0,0 @@
package middleware
import (
"net/http"
)
// RecoverFromPanic wraps an http.Handler and recovers from any panics that occur during its execution.
// If a panic occurs, it sends an HTTP 500 Internal Server Error response with the panic message.
func RecoverFromPanic(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var errorString string
defer func() {
r := recover()
if r != nil {
switch t := r.(type) {
case string:
errorString = t
case error:
errorString = t.Error()
default:
errorString = "Unknown error"
}
http.Error(w, errorString, http.StatusInternalServerError)
}
}()
h.ServeHTTP(w, r)
})
}