🏗️ microservice fabric splitting

This commit is contained in:
2024-12-24 00:38:41 +08:00
parent 462e811742
commit 89d64336f5
311 changed files with 18384 additions and 2428 deletions

View File

@@ -0,0 +1,26 @@
package utils
import (
"net"
"net/http"
"strings"
)
// GetClientIP returns the client IP address from the request.
func GetClientIP(r *http.Request) string {
xForwardedFor := strings.TrimSpace(r.Header.Get("X-Forwarded-For"))
if xForwardedFor != "" {
return strings.Split(xForwardedFor, ",")[0]
}
ip := strings.TrimSpace(r.Header.Get("X-Real-Ip"))
if ip != "" {
return ip
}
ip, _, err := net.SplitHostPort(strings.TrimSpace(r.RemoteAddr))
if err != nil {
return ""
}
return ip
}