Home > Article > Backend Development > How to retrieve user IP address in a Golang App Engine web application?
Retrieving User IP Address in a Golang App Engine Web Application
To successfully integrate reCAPTCHA into your GAE Golang web application, obtaining the user's IP address is essential. Here's a solution to fetch this information from a form post.
Utilize the net.SplitHostPort function:
ip, _, _ := net.SplitHostPort(r.RemoteAddr)
In this code, r represents the Request object from the HTTP request. net.SplitHostPort separates the host and port information from the r.RemoteAddr value, which stores the user's IP address. Assigning the result to variables ip, hostname, and port allows you to access the user's IP address in the ip variable.
The above is the detailed content of How to retrieve user IP address in a Golang App Engine web application?. For more information, please follow other related articles on the PHP Chinese website!