Files
huangguo_server/middleware/ip/ip.go
T
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

38 lines
861 B
Go

package ip
import (
"net/http"
"91porn-server/common/constant"
"91porn-server/common/stderr"
"91porn-server/models/v/ipwhitemod"
"91porn-server/web/webg"
"github.com/gin-gonic/gin"
)
// RealIP 获取真实IP
func RealIP(c *gin.Context) {
ip := c.ClientIP()
c.Set(constant.CtxIP, ip)
}
var accessForbidMsg = gin.H{
"code": stderr.ErrAccessForbid,
"msg": stderr.ErrAccessForbid.Msg(),
}
// RealIP 获取真实IP
func CheckWhiteIP(ctx *gin.Context) {
//检查ip是否在白名单中
// ipFlag, err := webg.Redis.SISMember(constant.IPWhiteRedisKey, constant.CtxIP)
// if webg.Conf.EnableIPWhite.IsEnable && (err != nil || !ipFlag) {
if webg.Conf.EnableIPWhite.IsEnable {
iPWhite, err := ipwhitemod.FindOneByIp(ctx.ClientIP())
if err != nil || iPWhite.IP == "" {
ctx.AbortWithStatusJSON(http.StatusOK, accessForbidMsg)
return
}
}
}