Skip to content

Instantly share code, notes, and snippets.

@squaredice
Created March 25, 2018 14:33
Show Gist options
  • Save squaredice/215bb9a934d4eb1cee105a3752323021 to your computer and use it in GitHub Desktop.
Save squaredice/215bb9a934d4eb1cee105a3752323021 to your computer and use it in GitHub Desktop.
Get client real ip
package main
import (
"fmt"
"github.com/Tomasen/realip"
"log"
"net/http"
)
//CheckClientIP show real client IP
func CheckClientIP(w http.ResponseWriter, r *http.Request) {
clientIP := realip.FromRequest(r)
fmt.Fprintf(w, "Hello, your ip is: %s", clientIP)
}
func main() {
fmt.Println("START")
http.HandleFunc("/", CheckClientIP)
log.Fatal(http.ListenAndServe(":80", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment