增加ip黑名单列表接口

pull/30/head
taoshihan1991 4 years ago
parent 1dfc6c342e
commit dd7ad61a5d

@ -2,7 +2,9 @@ package controller
import (
"github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/config"
"github.com/taoshihan1991/imaptool/models"
"strconv"
)
func PostIpblack(c *gin.Context) {
@ -21,3 +23,17 @@ func PostIpblack(c *gin.Context) {
"msg": "添加黑名单成功!",
})
}
func GetIpblacks(c *gin.Context) {
page,_:=strconv.Atoi(c.Query("page"))
count:=models.CountIps(nil,nil)
list:=models.FindIps(nil,nil,uint(page),config.VisitorPageSize)
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result":gin.H{
"list":list,
"count":count,
"pagesize":config.PageSize,
},
})
}

@ -22,3 +22,26 @@ func FindIp(ip string)Ipblack{
DB.Where("ip = ?", ip).First(&ipblack)
return ipblack
}
func FindIps(query interface{},args []interface{},page uint,pagesize uint)[]Ipblack{
offset:=(page-1)*pagesize
if offset<0{
offset=0
}
var ipblacks []Ipblack
if query!=nil{
DB.Where(query, args...).Offset(offset).Limit(pagesize).Find(&ipblacks)
}else{
DB.Offset(offset).Limit(pagesize).Find(&ipblacks)
}
return ipblacks
}
//查询条数
func CountIps(query interface{},args []interface{})uint{
var count uint
if query!=nil{
DB.Model(&Visitor{}).Where(query,args...).Count(&count)
}else{
DB.Model(&Visitor{}).Count(&count)
}
return count
}

@ -50,4 +50,5 @@ func InitApiRouter(engine *gin.Engine){
engine.DELETE("/notice",middleware.JwtApiMiddleware, controller.DelNotice)
engine.GET("/notices",middleware.JwtApiMiddleware, controller.GetNotices)
engine.POST("/ipblack",middleware.JwtApiMiddleware,controller.PostIpblack)
engine.POST("/ipblacks_all",middleware.JwtApiMiddleware,controller.GetIpblacks)
}
Loading…
Cancel
Save