【发布时间】:2025-11-23 06:05:01
【问题描述】:
我正在使用 gorilla/mux 在 golang 中实现一个 API 应用程序,这是一个强大的库,有助于构建 Web API,
但是我需要为每个客户保留 IP 地址,我如何才能为每个访问网站的客户获取 IP 地址?
代码:
func GetIpAddress(w http.ResponseWriter, r *http.Request){
// Whenever User visits this URL (this function)
// We have to know IP Address of user
output := r.UserAgent()
fmt.Print("Output : ", output)
// But var (output) returns whole string excluding clients ip address
}
【问题讨论】:
-
你能包含一些你到目前为止写的代码吗?
-
@17xande 你去...