Go package that can be used to get client's real public IP. Based on https://github.com/tomasen/realip.
- Parses IPs from
X-Real-IP
- Parses IPs from
X-Forwarded-For
- Excludes local/private address by default
- Custom filtering options for
X-Forwarded-For
IPs
package main
import "github.com/ripexz/rip"
func (h *Handler) ServeIndexPage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
clientIP := rip.FromRequest(r, nil)
log.Println("GET / from", clientIP)
}
clientIP := rip.FromRequest(r, rip.FilterAWS)
clientIP := rip.FromRequest(r, func(ips []string) (string, bool) {
// your custom logic here
return "127.0.0.1", true
})
Please make sure your code:
- Passes the configured golangci-lint checks.
- Passes the tests.