feat: 重建 Bell GoAdmin 产品骨架 (#62)

This commit is contained in:
QiuSW
2026-08-27 18:20:40 +08:00
parent b37c350096
commit f5a3dd796b
715 changed files with 75278 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
package common
import (
"github.com/gin-gonic/gin"
"strings"
)
func GetClientIP(c *gin.Context) string {
// 优先从 X-Forwarded-For 获取 IP
ip := c.Request.Header.Get("X-Forwarded-For")
if ip == "" || strings.Contains(ip, "127.0.0.1") {
// 如果为空或为本地地址,则尝试从 X-Real-IP 获取
ip = c.Request.Header.Get("X-real-ip")
}
if ip == "" {
// 如果仍为空,则使用 RemoteIP
ip = c.RemoteIP()
}
if ip == "" || ip == "127.0.0.1" {
// 如果仍为空或为本地地址,则使用 ClientIP
ip = c.ClientIP()
}
if ip == "" {
// 最后兜底为本地地址
ip = "127.0.0.1"
}
return ip
}