Sprint 8.1: /api/v1/debug/log endpoint для клиентских логов

This commit is contained in:
ga 2026-08-20 21:38:27 +00:00
parent 748b4a31fb
commit 249c3d2a8f
2 changed files with 29 additions and 0 deletions

View File

@ -225,6 +225,7 @@ func main() {
protected.Post("/auth/consents", consentH.Accept)
protected.Get("/auth/consents", consentH.Status)
protected.Post("/debug/log", h.DebugLog)
app.Get("/ws", ws.AuthMiddleware(authSvc), ws.Upgrade, ws.Handler(hub))

View File

@ -1,6 +1,7 @@
package handlers
import (
"log/slog"
"strings"
"time"
@ -321,3 +322,30 @@ func age(birth *time.Time) *int {
}
return &a
}
// DebugLog — клиент-сайд диагностика (приходит из JS через api.js)
type debugLogReq struct {
Path string `json:"path"`
Status int `json:"status"`
Ms int `json:"ms"`
UA string `json:"ua"`
Err string `json:"err,omitempty"`
IsTelegram bool `json:"is_telegram"`
}
func (h *Handlers) DebugLog(c *fiber.Ctx) error {
var req debugLogReq
if err := c.BodyParser(&req); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "bad body"})
}
slog.Info("client-debug",
"path", req.Path,
"status", req.Status,
"ms", req.Ms,
"is_tg", req.IsTelegram,
"ua", req.UA,
"err", req.Err,
"ip", c.IP(),
)
return c.JSON(fiber.Map{"ok": true})
}