feat: add trusted proxy identity and overload stats

This commit is contained in:
2026-09-22 18:19:39 +08:00
parent 2259606f72
commit 95dc4568f6
17 changed files with 346 additions and 42 deletions

View File

@@ -2,7 +2,6 @@ package middleware
import (
"fmt"
"net/http"
"time"
apierrors "git.yuntuo.hk/k2safe/go-omni/errors"
@@ -64,19 +63,9 @@ func AccessLog() httpx.Middleware {
"route", httpx.RoutePattern(ctx.Context()),
"status", status,
"durationMs", time.Since(started).Seconds()*1000,
"clientIp", clientIP(ctx.Request()),
"clientIp", ctx.ClientIP(),
)
return err
}
}
}
func clientIP(request *http.Request) string {
if request == nil {
return ""
}
if value := request.Header.Get("X-Forwarded-For"); value != "" {
return value
}
return request.RemoteAddr
}