feat: add forward client real IP
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user