feat: add forward client real IP

This commit is contained in:
Jonas Kaninda
2024-10-28 02:26:02 +01:00
parent fa6e102cd8
commit 8250c8ed5a
3 changed files with 24 additions and 10 deletions

View File

@@ -14,6 +14,7 @@ import (
"github.com/common-nighthawk/go-figure"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/jkaninda/goma-gateway/util"
"net/http"
)
func Intro() {
@@ -31,3 +32,12 @@ func printRoute(routes []Route) {
}
fmt.Println(t.Render())
}
func getRealIP(r *http.Request) string {
if ip := r.Header.Get("X-Real-IP"); ip != "" {
return ip
}
if ip := r.Header.Get("X-Forwarded-For"); ip != "" {
return ip
}
return r.RemoteAddr
}