Sprint 8.1: /api/v1/debug/log endpoint для клиентских логов
This commit is contained in:
parent
748b4a31fb
commit
249c3d2a8f
@ -225,6 +225,7 @@ func main() {
|
|||||||
|
|
||||||
protected.Post("/auth/consents", consentH.Accept)
|
protected.Post("/auth/consents", consentH.Accept)
|
||||||
protected.Get("/auth/consents", consentH.Status)
|
protected.Get("/auth/consents", consentH.Status)
|
||||||
|
protected.Post("/debug/log", h.DebugLog)
|
||||||
|
|
||||||
app.Get("/ws", ws.AuthMiddleware(authSvc), ws.Upgrade, ws.Handler(hub))
|
app.Get("/ws", ws.AuthMiddleware(authSvc), ws.Upgrade, ws.Handler(hub))
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log/slog"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -321,3 +322,30 @@ func age(birth *time.Time) *int {
|
|||||||
}
|
}
|
||||||
return &a
|
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})
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user