Something went wrong. Try again.
home to your local SPACEGIRL 💫 arimelody.space
Something went wrong. Try again.
698 B · 23 lines
Go
at dev
123456789101112131415161718192021222324package controller
import ( "arimelody-web/model" "net/http" "slices" "strings")
// Returns the request's original IP address, resolving the `x-forwarded-for`// header if the request originates from a trusted proxy.func ResolveIP(app *model.AppState, r *http.Request) string { addr := strings.Split(r.RemoteAddr, ":")[0] if slices.Contains(app.Config.TrustedProxies, addr) { forwardedFor := r.Header.Get("x-forwarded-for") if len(forwardedFor) > 0 { // discard extra IPs; cloudflare tends to append their nodes forwardedFor = strings.Split(forwardedFor, ", ")[0] return forwardedFor } } return addr}