代码拉取完成,页面将自动刷新
/*
* Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved.
* PilotGo-plugin-topology licensed under the Mulan Permissive Software License, Version 2.
* See LICENSE file for more details.
* Author: Wangjunqi123 <wangjunqi@kylinos.cn>
* Date: Thu Nov 7 16:33:56 2024 +0800
*/
package middleware
import (
"time"
"gitee.com/openeuler/PilotGo-plugin-topology/cmd/server/global"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
)
func Logger(_skipPaths []string) gin.HandlerFunc {
var skip map[string]struct{}
if len(_skipPaths) > 0 {
skip = make(map[string]struct{}, len(_skipPaths))
for _, path := range _skipPaths {
skip[path] = struct{}{}
}
}
return func(c *gin.Context) {
start := time.Now()
path := c.Request.URL.Path
raw := c.Request.URL.RawQuery
c.Next()
if _, ok := skip[path]; !ok {
endTime := time.Now()
latency := endTime.Sub(start)
method := c.Request.Method
statusCode := c.Writer.Status()
clientIP := c.ClientIP()
errorMessage := c.Errors.ByType(gin.ErrorTypePrivate).String()
if raw != "" {
path = path + "?" + raw
}
if latency > time.Minute {
latency = latency.Truncate(time.Second)
}
global.ERManager.ErrorTransmit("gin", "debug", errors.Errorf("|%3d|%-13v|%-15s|%-7s %#v\n%s",
statusCode,
latency,
clientIP,
method,
path,
errorMessage),
false, false,
)
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。