feat 改名
This commit is contained in:
37
Server/gateway/net/http_gateway/middleward.go
Normal file
37
Server/gateway/net/http_gateway/middleward.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package http_gateway
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
"time"
|
||||
)
|
||||
|
||||
func corsConfig() cors.Config {
|
||||
return cors.Config{
|
||||
AllowMethods: []string{"GET", "POST", "OPTIONS"},
|
||||
AllowHeaders: []string{"Content-Type", "Authorization"},
|
||||
AllowCredentials: false,
|
||||
AllowAllOrigins: true,
|
||||
MaxAge: 12 * time.Hour,
|
||||
}
|
||||
}
|
||||
|
||||
func ginLogger(logger *zap.SugaredLogger) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
start := time.Now()
|
||||
path := c.Request.URL.Path
|
||||
c.Next()
|
||||
cost := time.Since(start)
|
||||
|
||||
logger.Infof(fmt.Sprintf(
|
||||
"HTTP Method:%v Code:%v Time:%v IP:%v Path:%v",
|
||||
c.Request.Method,
|
||||
c.Writer.Status(),
|
||||
cost,
|
||||
c.ClientIP(),
|
||||
path),
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user