This commit is contained in:
孟帅
2023-05-10 23:54:50 +08:00
parent bbe655a4d8
commit 49a96750bf
314 changed files with 15138 additions and 6244 deletions

View File

@@ -3,7 +3,6 @@
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
package hook
import (
@@ -21,14 +20,16 @@ func (s *sHook) accessLog(r *ghttp.Request) {
if r.IsFileRequest() {
return
}
var ctx = r.Context()
var ctx = contexts.Detach(r.Context())
modelCtx := contexts.Get(ctx)
if modelCtx == nil {
return
}
// 计算运行耗时
contexts.SetTakeUpTime(ctx, gtime.TimestampMilli()-r.EnterTime)
contexts.SetDataMap(ctx, g.Map{
"request.takeUpTime": gtime.TimestampMilli() - r.EnterTime,
// ...
})
simple.SafeGo(ctx, func(ctx context.Context) {
if err := service.SysLog().AutoLog(ctx); err != nil {

View File

@@ -3,7 +3,6 @@
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
package hook
import (
@@ -22,6 +21,10 @@ func New() *sHook {
return &sHook{}
}
func (s *sHook) BeforeServe(r *ghttp.Request) {
}
func (s *sHook) AfterOutput(r *ghttp.Request) {
s.accessLog(r)
s.lastAdminActive(r)

View File

@@ -66,7 +66,7 @@ func (s *sHook) lastAdminActive(r *ghttp.Request) {
}
var (
ctx = r.Context()
ctx = contexts.Detach(r.Context())
member = contexts.GetUser(ctx)
)
@@ -76,7 +76,8 @@ func (s *sHook) lastAdminActive(r *ghttp.Request) {
if allow(member.Id) {
simple.SafeGo(ctx, func(ctx context.Context) {
_, err := g.Model("admin_member").Ctx(ctx).
_, err := g.Model("admin_member").
Ctx(ctx).
Where("id", member.Id).
WhereLT("last_active_at", gtime.Now()).
Data(g.Map{"last_active_at": gtime.Now()}).