chore(go): simplify sourceIP logic

This commit is contained in:
Guanran Wang 2024-10-19 16:18:59 +08:00
parent 796b0b3839
commit 265c998df0
Signed by: nyancat
GPG key ID: 91F97D9ED12639CF

View file

@ -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]
}()