修bug
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
||||
func AuditLogMiddleware(ctx context.Context, auditService service.AuditService) echo.MiddlewareFunc {
|
||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
newCtx := logs.AddFuncName(ctx, c.Request().Context(), "AuditLogMiddleware")
|
||||
newCtx := logs.AddFuncName(c.Request().Context(), ctx, "AuditLogMiddleware")
|
||||
|
||||
// 首先执行请求链中的后续处理程序(即业务控制器)
|
||||
err := next(c)
|
||||
@@ -48,9 +48,12 @@ func AuditLogMiddleware(ctx context.Context, auditService service.AuditService)
|
||||
status, _ := c.Get(models.ContextAuditStatus.String()).(models.AuditStatus)
|
||||
resultDetails, _ := c.Get(models.ContextAuditResultDetails.String()).(string)
|
||||
|
||||
// 为异步任务创建一个分离的 Context,以防止原始请求的 Context 被取消
|
||||
detachedCtx := logs.DetachContext(newCtx)
|
||||
|
||||
// 调用审计服务记录日志(异步)
|
||||
auditService.LogAction(
|
||||
newCtx,
|
||||
detachedCtx,
|
||||
user,
|
||||
reqCtx,
|
||||
actionType,
|
||||
|
||||
Reference in New Issue
Block a user