From b84f0b73df411840f568f3db71b4580ceadb5fb2 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Mon, 29 Jul 2024 15:54:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E5=87=BA=E6=B5=8B=E8=AF=95=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E9=AA=8C=E8=AF=81=E7=A0=81=E5=88=A4=E6=96=AD1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/service/Public.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/api/service/Public.go b/api/service/Public.go index 8bd62af..d529e36 100644 --- a/api/service/Public.go +++ b/api/service/Public.go @@ -8,6 +8,7 @@ import ( "hepa-calc-api/extend/aliyun" "hepa-calc-api/global" "math/rand" + "net/http" "strconv" "time" ) @@ -121,3 +122,12 @@ func (r *PublicService) GetIndex(userId int64) (g *dto.IndexDto, err error) { return g, nil } + +// GetUserIP 获取用户ip +func (r *PublicService) GetUserIP(h *http.Request) string { + forwarded := h.Header.Get("X-FORWARDED-FOR") + if forwarded != "" { + return forwarded + } + return h.RemoteAddr +}