From 265c998df0c56b351854e599967cc3e0eebd2e79 Mon Sep 17 00:00:00 2001 From: Guanran Wang Date: Sat, 19 Oct 2024 16:18:59 +0800 Subject: [PATCH] chore(go): simplify sourceIP logic --- main.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/main.go b/main.go index e59037e..9dc3a3f 100644 --- a/main.go +++ b/main.go @@ -80,11 +80,8 @@ func getIPCountry(ip string) string { func handleRequest(w http.ResponseWriter, r *http.Request) { sourceIP := func() string { - if ip := r.Header.Get("CF-Connecting-IP"); ip != "" { - return ip - } if ip := r.Header.Get("X-Forwarded-For"); ip != "" { - return ip + return strings.Split(ip, ",")[0] } return strings.Split(r.RemoteAddr, ":")[0] }()