forked from mtusi2026/mtusi2026lab3
- X-Instance-Id, обязательный Idempotency-Key (PostgreSQL, одна транзакция) - HAProxy + 2..N реплик API, readiness/drain по SIGTERM, однократные миграции - скрипты stop-one/restore/restart/rolling-update/collect-evidence - трек 1: параметризованный стенд, cmd/bench, оркестратор и анализ - workflow реального прогона Docker-стенда на GitHub Actions Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
26 lines
538 B
Go
26 lines
538 B
Go
package middleware
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
"github.com/charawein/mtusi2026lab3/internal/transport/httputil"
|
|
)
|
|
|
|
func Recovery(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
defer func() {
|
|
if rec := recover(); rec != nil {
|
|
slog.Error("panic in handler",
|
|
"panic", rec,
|
|
"request_id", httputil.RequestIDFrom(r.Context()),
|
|
"method", r.Method,
|
|
"path", r.URL.Path,
|
|
)
|
|
httputil.WriteError(w, r, nil)
|
|
}
|
|
}()
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|