调整工厂模式的方法

This commit is contained in:
2025-12-05 00:07:15 +08:00
parent 0650feb0d2
commit 6146178111
15 changed files with 635 additions and 1039 deletions

View File

@@ -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 != "" {