intial commit

This commit is contained in:
2026-05-25 11:45:56 +05:30
commit 6ab508560f
73 changed files with 23713 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
package middlewares
import (
"time"
"nearle/utils"
"github.com/gofiber/fiber/v2"
)
// ZapLogger is a Fiber middleware that logs HTTP requests using Zap.
func ZapLogger() fiber.Handler {
return func(c *fiber.Ctx) error {
start := time.Now()
// Handle the request
err := c.Next()
latency := time.Since(start).String()
status := c.Response().StatusCode()
method := c.Method()
path := c.Path()
ip := c.IP()
fields := []interface{}{
"status", status,
"method", method,
"path", path,
"ip", ip,
"latency", latency,
}
if err != nil {
fields = append(fields, "error", err.Error())
utils.Logger.Errorw("API Request Failed", fields...)
return err
}
utils.Logger.Infow("API Request Successful", fields...)
return nil
}
}