31 lines
585 B
Go
31 lines
585 B
Go
package middleware
|
|
|
|
import (
|
|
"allapp/db"
|
|
"allapp/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(userID int64) {
|
|
ctx := context.Background()
|
|
|
|
if err := db.Queries.UpdateUserLastLoginTime(ctx, userID); err != nil {
|
|
logx.CtxError(ctx, "刷新用户活跃时间失败, userID=%d, err=%v", userID, err)
|
|
}
|
|
}(userID)
|
|
}
|
|
}
|