This commit is contained in:
rl544
2026-09-15 01:38:15 +09:00
parent e748221831
commit 4e8a65f40d
16 changed files with 906 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
package middleware
import (
"log"
"net/http"
)
// Recovery is a middleware that recovers from any panics and writes a 500 if there was one
func Recovery() Middleware {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
log.Printf("PANIC RECOVERED: %v", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}
}()
next.ServeHTTP(w, r)
})
}
}