* fix(security): harden auth and credential handling (HH-444) * fix(security): address HH-444 review blockers * fix(security): close remaining HH-444 review blockers --------- Co-authored-by: Rogee <rogee@ipao.vip>
30 lines
604 B
Go
30 lines
604 B
Go
package middleware
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
applogger "github.com/gochat/gochat/pkg/logger"
|
|
)
|
|
|
|
// RequestLogger logs structured request information.
|
|
// Pattern follows Chatwoot's Rails request logging middleware.
|
|
func RequestLogger() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
start := time.Now()
|
|
path := c.Request.URL.Path
|
|
method := c.Request.Method
|
|
|
|
c.Next()
|
|
|
|
latency := time.Since(start)
|
|
status := c.Writer.Status()
|
|
if route := c.FullPath(); route != "" {
|
|
path = route
|
|
}
|
|
|
|
applogger.L().Infof("HTTP %s %s %d %v",
|
|
method, path, status, latency)
|
|
}
|
|
}
|