重构日志与可观测性体系
新增单行文本编码器与结构化 GORM 日志,统一错误记录与请求日志策略,收紧日志文件权限并修复按天切分与压缩,支付回调参数脱敏,生产强制阿里云短信,RequestID 校验防注入,日志文案中文化。
This commit is contained in:
@@ -40,6 +40,7 @@ func (h *Handler) List(c *gin.Context) {
|
||||
|
||||
resp, err := h.service.List(c.Request.Context(), query)
|
||||
if err != nil {
|
||||
response.RecordError(c, err)
|
||||
response.Error(c, http.StatusInternalServerError, "internal_error", "查询失败")
|
||||
return
|
||||
}
|
||||
@@ -78,6 +79,7 @@ func (h *Handler) Get(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
response.RecordError(c, err)
|
||||
response.Error(c, http.StatusInternalServerError, "internal_error", "查询失败")
|
||||
return
|
||||
}
|
||||
@@ -99,16 +101,19 @@ func (h *Handler) ExportBackup(c *gin.Context) {
|
||||
|
||||
backup, err := h.service.ExportBackup(c.Request.Context(), adminID, auditMeta(c))
|
||||
if err == ErrDecryptionFailed {
|
||||
response.RecordError(c, err)
|
||||
response.Error(c, http.StatusInternalServerError, "decrypt_failed", "密钥解密失败")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
response.RecordError(c, err)
|
||||
response.Error(c, http.StatusInternalServerError, "internal_error", "导出失败")
|
||||
return
|
||||
}
|
||||
|
||||
data, err := json.MarshalIndent(backup, "", " ")
|
||||
if err != nil {
|
||||
response.RecordError(c, err)
|
||||
response.Error(c, http.StatusInternalServerError, "internal_error", "导出失败")
|
||||
return
|
||||
}
|
||||
@@ -148,10 +153,12 @@ func (h *Handler) ImportBackup(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if err == ErrEncryptionFailed {
|
||||
response.RecordError(c, err)
|
||||
response.Error(c, http.StatusInternalServerError, "encrypt_failed", "密钥加密失败")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
response.RecordError(c, err)
|
||||
response.Error(c, http.StatusInternalServerError, "internal_error", "导入失败")
|
||||
return
|
||||
}
|
||||
@@ -187,6 +194,7 @@ func (h *Handler) Create(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
response.RecordError(c, err)
|
||||
response.Error(c, http.StatusInternalServerError, "internal_error", "创建失败")
|
||||
return
|
||||
}
|
||||
@@ -230,6 +238,7 @@ func (h *Handler) Update(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
response.RecordError(c, err)
|
||||
response.Error(c, http.StatusInternalServerError, "internal_error", "更新失败")
|
||||
return
|
||||
}
|
||||
@@ -266,6 +275,7 @@ func (h *Handler) Delete(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
response.RecordError(c, err)
|
||||
response.Error(c, http.StatusInternalServerError, "internal_error", "删除失败")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user