refactor: 移动目录
This commit is contained in:
parent
5f831c7005
commit
9ad207f6c9
@ -5,13 +5,13 @@
|
||||
// Distributed under terms of the MIT license.
|
||||
//
|
||||
|
||||
package middleware
|
||||
package cors
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"git.hexq.cn/tiglog/golib/helper"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func NewCors(origins []string) gin.HandlerFunc {
|
@ -5,7 +5,7 @@
|
||||
// Distributed under terms of the MIT license.
|
||||
//
|
||||
|
||||
package middleware_test
|
||||
package cors_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -13,15 +13,15 @@ import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"git.hexq.cn/tiglog/golib/gtest"
|
||||
"git.hexq.cn/tiglog/golib/middleware"
|
||||
"git.hexq.cn/tiglog/golib/gweb/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func newTestRouter(origins []string) *gin.Engine {
|
||||
gin.SetMode(gin.TestMode)
|
||||
router := gin.New()
|
||||
router.Use(middleware.NewCors(origins))
|
||||
router.Use(cors.NewCors(origins))
|
||||
router.GET("/", func(c *gin.Context) {
|
||||
c.String(http.StatusOK, "get")
|
||||
})
|
@ -5,7 +5,7 @@
|
||||
// Distributed under terms of the MIT license.
|
||||
//
|
||||
|
||||
package middleware
|
||||
package ginlog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -32,8 +32,7 @@ func GinLogger(logfile string) gin.HandlerFunc {
|
||||
if latency > time.Minute {
|
||||
latency = latency.Truncate(time.Second)
|
||||
}
|
||||
|
||||
log.Info("GIN request",
|
||||
fields := []logger.Field{
|
||||
logger.String("start", start.Format(time.RFC3339)),
|
||||
logger.Int("status", c.Writer.Status()),
|
||||
logger.String("latency", fmt.Sprintf("%s", latency)),
|
||||
@ -43,6 +42,11 @@ func GinLogger(logfile string) gin.HandlerFunc {
|
||||
logger.String("clientIP", c.ClientIP()),
|
||||
logger.String("userAgent", c.Request.UserAgent()),
|
||||
logger.String("error", c.Errors.ByType(gin.ErrorTypePrivate).String()),
|
||||
)
|
||||
}
|
||||
if requestID := c.Writer.Header().Get("X-Request-Id"); requestID != "" {
|
||||
fields = append(fields, logger.String("request_id", requestID))
|
||||
}
|
||||
|
||||
log.Info("GIN request", fields...)
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
// Distributed under terms of the MIT license.
|
||||
//
|
||||
|
||||
package middleware
|
||||
package ginlog
|
||||
|
||||
import (
|
||||
"errors"
|
Loading…
Reference in New Issue
Block a user