28 lines
547 B
Go
28 lines
547 B
Go
package middleware
|
|
|
|
import (
|
|
"cn/oneao/base-go/db"
|
|
"cn/oneao/base-go/logx"
|
|
"context"
|
|
"github.com/cloudwego/hertz/pkg/app"
|
|
)
|
|
|
|
func RefreshActive() app.HandlerFunc {
|
|
return func(c context.Context, ctx *app.RequestContext) {
|
|
// 先执行后续 handler
|
|
ctx.Next(c)
|
|
|
|
userID := GetUserID(c)
|
|
if userID == 0 {
|
|
return
|
|
}
|
|
|
|
// 异步刷新活跃时间
|
|
go func() {
|
|
if err := db.Queries.UpdateUserActiveTime(c, userID); err != nil {
|
|
logx.CtxError(c, "刷新用户活跃时间失败, userID=%d, err=%v", userID, err)
|
|
}
|
|
}()
|
|
}
|
|
}
|