✨ 新增几大中心功能
This commit is contained in:
34
server/middleware/app_activity.go
Normal file
34
server/middleware/app_activity.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
appSvc "git.echol.cn/loser/Go-Web-Template/server/service/app"
|
||||
"git.echol.cn/loser/Go-Web-Template/server/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// AppActivity 玩家端活跃记录:每次请求写 last_active_at(轻量 upsert)
|
||||
func AppActivity() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.Next()
|
||||
|
||||
uid := utils.GetUserID(c)
|
||||
if uid == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// 避免极端高频写:简单节流(同请求链路内只写一次即可)
|
||||
if _, exists := c.Get("__app_activity_written"); exists {
|
||||
return
|
||||
}
|
||||
c.Set("__app_activity_written", true)
|
||||
|
||||
// 尽量不阻塞响应:允许轻微延迟
|
||||
go func(userID uint, ip string) {
|
||||
_ = appSvc.AppActivityServiceApp.TouchActive(userID, ip)
|
||||
}(uid, c.ClientIP())
|
||||
|
||||
_ = time.Now() // 保留 import time,避免未来扩展时频繁改动(不影响逻辑)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user