ЛР 2: PostgreSQL, сессии в Valkey, кэш истории (трек 1)

This commit is contained in:
Нурлыгаянова Екатерина
2026-10-29 11:29:38 +03:00
parent 65003b6119
commit 1503b5db81
132 changed files with 15114 additions and 20 deletions
@@ -0,0 +1,32 @@
package middleware
import (
"log/slog"
"net/http"
"runtime/debug"
"github.com/labstack/echo/v4"
)
func Recover(logger *slog.Logger) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) (err error) {
defer func() {
r := recover()
if r == nil {
return
}
rid, _ := c.Get(RequestIDKey).(string)
logger.Error("panic recovered",
slog.String("request_id", rid),
slog.String("method", c.Request().Method),
slog.String("path", c.Request().URL.Path),
slog.Any("panic", r),
slog.String("stack", string(debug.Stack())),
)
err = echo.NewHTTPError(http.StatusInternalServerError, "Internal server error")
}()
return next(c)
}
}
}