限流定时清除内存

pull/23/head
630892807@qq.com 4 years ago
parent b75b3f6cfa
commit 29aceb65a0

@ -25,7 +25,11 @@ func SendServerJiang(title string, content string, domain string) string {
res := tools.Get(url)
return res
}
func SendVisitorLoginNotice(kefuName, visitorName, avator, content string) {
func SendVisitorLoginNotice(kefuName, visitorName, avator, content, visitorId string) {
if !tools.LimitFreqSingle("sendnotice:"+visitorId, 1, 120) {
log.Println("SendVisitorLoginNotice limit")
return
}
userInfo := make(map[string]string)
userInfo["username"] = visitorName
userInfo["avator"] = avator

@ -117,7 +117,7 @@ func PostVisitorLogin(c *gin.Context) {
//各种通知
go SendNoticeEmail(visitor.Name, "来了")
go SendAppGetuiPush(kefuInfo.Name, visitor.Name, visitor.Name+"来了")
go SendVisitorLoginNotice(kefuInfo.Name, visitor.Name, visitor.Avator, visitor.Name+"来了")
go SendVisitorLoginNotice(kefuInfo.Name, visitor.Name, visitor.Avator, visitor.Name+"来了", visitor.VisitorId)
go ws.VisitorOnline(kefuInfo.Name, visitor)
go SendServerJiang(visitor.Name, "来了", c.Request.Host)

@ -1,10 +1,31 @@
package tools
import "time"
import (
"log"
"time"
)
var LimitQueue map[string][]int64
var ok bool
func init() {
cleanLimitQueue()
}
func cleanLimitQueue() {
go func() {
for {
LimitQueue = nil
log.Println("cleanLimitQueue finshed")
now := time.Now()
// 计算下一个零点
next := now.Add(time.Hour * 24)
next = time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location())
t := time.NewTimer(next.Sub(now))
<-t.C
}
}()
}
//单机时间滑动窗口限流法
func LimitFreqSingle(queueName string, count uint, timeWindow int64) bool {
currTime := time.Now().Unix()

Loading…
Cancel
Save