lookupIP returns the request's IP
(r *http.Request)
| 105 | |
| 106 | // lookupIP returns the request's IP |
| 107 | func lookupIP(r *http.Request) string { |
| 108 | realIP := r.Header.Get("X-Real-IP") |
| 109 | forwardedFor := r.Header.Get("X-Forwarded-For") |
| 110 | |
| 111 | if forwardedFor != "" { |
| 112 | parts := strings.Split(forwardedFor, ",") |
| 113 | return parts[0] |
| 114 | } |
| 115 | |
| 116 | if realIP != "" { |
| 117 | return realIP |
| 118 | } |
| 119 | |
| 120 | return r.RemoteAddr |
| 121 | } |
| 122 | |
| 123 | // Limit is a middleware to rate limit the handler |
| 124 | func (rl *RateLimiter) Limit(next http.Handler) http.HandlerFunc { |