3 Star 17 Fork 4

eyebluecn/tank

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
util_network.go 438 Bytes
一键复制 编辑 原始数据 按行查看 历史
logzc 提交于 2017-12-23 18:02 +08:00 . init the project
package rest
import (
"net/http"
"strings"
)
//根据一个请求,获取ip.
func GetIpAddress(r *http.Request) string {
var ipAddress string
ipAddress = r.RemoteAddr
if ipAddress != "" {
ipAddress = strings.Split(ipAddress, ":")[0]
}
for _, h := range []string{"X-Forwarded-For", "X-Real-Ip"} {
for _, ip := range strings.Split(r.Header.Get(h), ",") {
if ip != "" {
ipAddress = ip
}
}
}
return ipAddress
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/eyebluecn/tank.git
git@gitee.com:eyebluecn/tank.git
eyebluecn
tank
tank
v1.0.5

搜索帮助