This commit is contained in:
oneao committed 2026-02-26 17:31:08 +08:00
1 parent 4ce951dd56
commit 8a3dea8545
44 files changed
+1599 -30

No files matched your search

@@ -0,0 +1,33 @@
package middleware
import (
"context"
"time"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/log"
)
func Logger() fiber.Handler {
return func(c fiber.Ctx) error {
ctx := context.WithValue(c.Context(), "request_id", c.RequestID())
c.SetContext(ctx)
start := time.Now()
err := c.Next()
duration := time.Since(start)
// 记录日志
log.Infow("API Request",
"method", c.Method(),
"path", c.Path(),
"status", c.Response().StatusCode(),
"duration", duration.String(),
"ip", c.IP(),
)
return err
}
}