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 } } }