调整工厂模式的方法
This commit is contained in:
@@ -123,7 +123,7 @@ func shouldSkipPath(path string, skipPaths []string) bool {
|
||||
// logHTTPRequest 记录HTTP请求日志
|
||||
func logHTTPRequest(log *logger.Logger, r *http.Request, rw *responseWriter, duration time.Duration) {
|
||||
// 获取客户端IP
|
||||
clientIP := getClientIP(r)
|
||||
clientIP := GetClientIP(r)
|
||||
|
||||
// 构建日志字段
|
||||
fields := map[string]interface{}{
|
||||
@@ -188,9 +188,9 @@ func formatValue(v interface{}) string {
|
||||
}
|
||||
}
|
||||
|
||||
// getClientIP 获取客户端真实IP
|
||||
// GetClientIP 获取客户端真实IP
|
||||
// 优先级:X-Forwarded-For > X-Real-IP > RemoteAddr
|
||||
func getClientIP(r *http.Request) string {
|
||||
func GetClientIP(r *http.Request) string {
|
||||
// 尝试从 X-Forwarded-For 获取
|
||||
xff := r.Header.Get("X-Forwarded-For")
|
||||
if xff != "" {
|
||||
|
||||
Reference in New Issue
Block a user