func GetIPAddressFromRequest(r *http.Request) string {
	forwardedAddress := r.Header.Get("X-Forwarded-For")
	if forwardedAddress != "" {
		clientAddress := strings.TrimSpace(strings.Split(forwardedAddress, ",")[0])
		return remoteAddressToSimpleIP(clientAddress)
	}
	standardForwardedHeader := r.Header.Get("Forwarded")
	if standardForwardedHeader != "" {
		targetPrefix := "for="
		for _, part := range strings.Split(standardForwardedHeader, ";") {
			trimmed := strings.TrimSpace(part)
			if strings.HasPrefix(trimmed, targetPrefix) {
				address := remoteAddressToSimpleIP(strings.TrimPrefix(trimmed, targetPrefix))
				return strings.NewReplacer("`", "", "'", "", "\"", "", "[", "", "]", "").Replace(address)
			}
		}
	}
	return remoteAddressToSimpleIP(r.RemoteAddr)
}
GetIPAddressFromRequest extracts the clients IP address from the request.
This function respects forwarding headers.
package api
import (
	"net/http"
	"os"
	"strings"
)
var RootPath string
func init() {
	rootPath, rootPathAvailable := os.LookupEnv("ROOT_PATH")
	if rootPathAvailable && rootPath != "" {
		RootPath = rootPath
	}
}
func SetupRoutes() {
	http.HandleFunc(RootPath+"/v1/stats", statsEndpoint)
	http.HandleFunc(RootPath+"/v1/ws", wsEndpoint)
	http.HandleFunc(RootPath+"/v1/lobby", lobbyEndpoint)
	http.HandleFunc(RootPath+"/v1/lobby/player", enterLobbyEndpoint)
}
func remoteAddressToSimpleIP(input string) string {
	address := input
	lastIndexOfDoubleColon := strings.LastIndex(address, ":")
	if lastIndexOfDoubleColon != -1 {
		address = address[:lastIndexOfDoubleColon]
	}
	return strings.TrimSuffix(strings.TrimPrefix(address, "["), "]")
}