feat(quality): Q5 后端错误处理治理扩展 — RDP/API Token/AIOps 模块 8 处 _ = DB 写入改为 log.Printf
Q4 修复了 controller/ 层 8 处 DB 写入的 _ = 静默忽略,但后续合并的 RDP
远程桌面、API Token、AIOps 告警分析等模块引入了新的 _ = DB 写入忽略。
本次将 controller/middleware 层所有 DB 写入操作(Create/Update/Updates)
的 _ = 静默忽略改为带 log.Printf 错误日志(不阻断业务流程)。
修改文件 (6):
- middleware/auth.go: API 密钥最后使用时间更新
- controller/terminal_session.go: 终端回放审计日志 + 修复 log 变量遮蔽
- controller/user_api_token.go: API 密钥默认值补全
- controller/rdp.go: RDP 会话结束状态 + 命令记录
- controller/rdp_session.go: 会话终止 + 回放审计 + 修复 log 变量遮蔽
- controller/aiops_alert_analysis.go: AI 告警分析结果保存
修复 2 处 Go 变量名遮蔽陷阱(log := model.AuditLog{} 遮蔽 "log" 包 → auditLog)
保留 4 处可接受忽略(1 DB 读取 + 3 WebSocket 帧写入)
验证: go build=0, 17/17 集成测试通过, Docker healthy
This commit is contained in:
1 parent
da9fd1e987
commit
cd30af5bd6
8 files changed
+63
-11
No files matched your search
@@ -3,6 +3,7 @@ package controller
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"time"
|
||||
@@ -136,7 +137,9 @@ func (h *UserHandler) ensureAPIKeyMeta(user *model.User) {
|
||||
user.ApiAccessKeyDurationMonths = defaultAPIKeyMonths
|
||||
}
|
||||
if len(patches) > 0 {
|
||||
_ = h.db.Model(&model.User{}).Where("id = ?", user.ID).Updates(patches).Error
|
||||
if err := h.db.Model(&model.User{}).Where("id = ?", user.ID).Updates(patches).Error; err != nil {
|
||||
log.Printf("[UserApiKey] 补全 API 密钥默认值失败 (user_id=%d): %v", user.ID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user