(r *http.Request)
| 7 | ) |
| 8 | |
| 9 | func ClientIP(r *http.Request) string { |
| 10 | xForwardedFor := r.Header.Get("X-Forwarded-For") |
| 11 | ip := strings.TrimSpace(strings.Split(xForwardedFor, ",")[0]) |
| 12 | if ip != "" { |
| 13 | return ip |
| 14 | } |
| 15 | |
| 16 | ip = strings.TrimSpace(r.Header.Get("X-Real-Ip")) |
| 17 | if ip != "" { |
| 18 | return ip |
| 19 | } |
| 20 | |
| 21 | if ip, _, err := net.SplitHostPort(strings.TrimSpace(r.RemoteAddr)); err == nil { |
| 22 | return ip |
| 23 | } |
| 24 | |
| 25 | return "" |
| 26 | } |
| 27 | |
| 28 | func IsLocalIPAddr(ip string) bool { |
| 29 | return IsLocalIP(net.ParseIP(ip)) |
no test coverage detected