Skip to content

Instantly share code, notes, and snippets.

@orcaman
Created September 9, 2014 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orcaman/9b8dd3f84550d7faac38 to your computer and use it in GitHub Desktop.
Save orcaman/9b8dd3f84550d7faac38 to your computer and use it in GitHub Desktop.
Util function to get "Real" IP address in Go
package main
import (
"net"
"net/http"
)
func getIP(r *http.Request) string {
if ipProxy := r.Header.Get("X-FORWARDED-FOR"); len(ipProxy) > 0 {
return ipProxy
}
ip, _, _ := net.SplitHostPort(r.RemoteAddr)
return ip
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment