chore: update code comment in english (#52)

This commit is contained in:
silenceqi 2024-12-20 15:55:15 +08:00 committed by GitHub
parent 4d52f2882a
commit 34f2f3bcce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 4 deletions

View File

@ -33,20 +33,20 @@ import (
"strings"
)
// GetClientIP 获取客户端 IP 地址
// GetClientIP retrieves the client's IP address
func GetClientIP(req *http.Request) string {
h := new(api.Handler)
// 1. 尝试从 XFF 头获取
// 1. Try to get the client IP from the X-Forwarded-For header and return the first IP address in the list
xff := h.GetHeader(req, "X-Forwarded-For", "")
clientIP := strings.Split(xff, ",")[0]
if len(clientIP) > 0 {
return clientIP
}
// 2. 尝试从 X-Real-IP 头获取
// 2. Try to get the client IP from the X-Real-IP header
clientIP = h.GetHeader(req, "X-Real-IP", "")
if len(clientIP) > 0 {
return clientIP
}
// 3. 从 RemoteAddr 获取
// 3. retrieve IP from request RemoteAddr
return strings.Split(req.RemoteAddr, ":")[0]
}