feat: add new features such as database watchdog

This commit is contained in:
DaanSelen
2026-04-21 16:27:04 +02:00
parent 610fdffdb8
commit c4a4fafb52
16 changed files with 428 additions and 158 deletions
+34
View File
@@ -0,0 +1,34 @@
package api
import (
"log/slog"
"time"
"github.com/gin-gonic/gin"
)
func slogMiddleware(logger *slog.Logger) gin.HandlerFunc {
return func(c *gin.Context) {
start := time.Now()
path := c.Request.URL.Path
query := c.Request.URL.RawQuery
c.Next()
logger.Info("request",
slog.String("method", c.Request.Method),
slog.String("path", path),
slog.String("query", query),
slog.Int("status", c.Writer.Status()),
slog.Duration("latency", time.Since(start)),
slog.String("client_ip", c.ClientIP()),
slog.Int("body_size", c.Writer.Size()),
)
if len(c.Errors) > 0 {
for _, err := range c.Errors {
logger.Error("request error", slog.String("error", err.Error()))
}
}
}
}