Base Project

This commit is contained in:
Tran Anh Tuan
2026-05-08 14:32:24 +07:00
parent 5a9249c9ea
commit 6a4a96e0ca
74 changed files with 6749 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
package middlewares
import (
"time"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
)
func LoggingMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
start := time.Now()
log.Info().
Str("type", "request").
Str("method", c.Request.Method).
Str("path", c.Request.URL.Path).
Str("ip", c.ClientIP()).
Str("query", c.Request.URL.RawQuery).
Time("time", start).
Msg("incoming request")
c.Next()
log.Info().
Str("type", "response").
Str("method", c.Request.Method).
Str("path", c.Request.URL.Path).
Int("status", c.Writer.Status()).
Dur("latency", time.Since(start)).
Time("time", time.Now()).
Msg("outgoing response")
}
}