项目初始化

This commit is contained in:
2025-12-10 19:03:24 +08:00
commit 04d920aa92
14 changed files with 909 additions and 0 deletions

37
middleware/logger.go Normal file
View File

@@ -0,0 +1,37 @@
package middleware
import (
"time"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)
// Logger 日志中间件
func Logger() gin.HandlerFunc {
return func(c *gin.Context) {
start := time.Now()
path := c.Request.URL.Path
raw := c.Request.URL.RawQuery
c.Next()
latency := time.Since(start)
clientIP := c.ClientIP()
method := c.Request.Method
statusCode := c.Writer.Status()
if raw != "" {
path = path + "?" + raw
}
logrus.WithFields(logrus.Fields{
"status_code": statusCode,
"latency": latency,
"client_ip": clientIP,
"method": method,
"path": path,
}).Info("HTTP Request")
}
}