Created
March 25, 2018 14:33
-
-
Save squaredice/215bb9a934d4eb1cee105a3752323021 to your computer and use it in GitHub Desktop.
Get client real ip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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