mirror of
https://github.com/veops/oneterm.git
synced 2025-10-21 14:29:24 +08:00
refactor(backend): optimize code organization structure
This commit is contained in:
27
backend/internal/api/middleware/logger.go
Normal file
27
backend/internal/api/middleware/logger.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/veops/oneterm/pkg/logger"
|
||||
)
|
||||
|
||||
func LoggerMiddleware() gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
start := time.Now()
|
||||
|
||||
ctx.Next()
|
||||
|
||||
cost := time.Since(start)
|
||||
logger.L().Info(ctx.Request.URL.String(),
|
||||
zap.String("method", ctx.Request.Method),
|
||||
zap.Int("status", ctx.Writer.Status()),
|
||||
zap.String("ip", ctx.ClientIP()),
|
||||
zap.Duration("cost", cost),
|
||||
)
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user