重构日志与可观测性体系

新增单行文本编码器与结构化 GORM 日志,统一错误记录与请求日志策略,收紧日志文件权限并修复按天切分与压缩,支付回调参数脱敏,生产强制阿里云短信,RequestID 校验防注入,日志文案中文化。
This commit is contained in:
yml2213
2026-07-29 16:19:35 +08:00
parent e75f1a8519
commit 88d74aca7d
64 changed files with 896 additions and 277 deletions
@@ -22,6 +22,7 @@ func NewHandler(service *Service) *Handler {
func (h *Handler) ListCategories(c *gin.Context) {
items, err := h.service.ListPublicCategories(c.Request.Context())
if err != nil {
response.RecordError(c, err)
response.InternalServerError(c, "获取分类失败")
return
}
@@ -36,6 +37,7 @@ func (h *Handler) ListProducts(c *gin.Context) {
query.Page, query.PageSize = parsePagination(c)
result, err := h.service.ListPublicProducts(c.Request.Context(), query)
if err != nil {
response.RecordError(c, err)
response.InternalServerError(c, "获取商品列表失败")
return
}
@@ -84,6 +86,7 @@ func (h *Handler) ListMyOrders(c *gin.Context) {
query.Page, query.PageSize = parsePagination(c)
result, err := h.service.ListOrdersForUser(c.Request.Context(), userID, query)
if err != nil {
response.RecordError(c, err)
response.InternalServerError(c, "获取订单列表失败")
return
}
@@ -133,6 +136,7 @@ func (h *Handler) CancelMyOrder(c *gin.Context) {
func (h *Handler) AdminListCategories(c *gin.Context) {
items, err := h.service.AdminListCategories(c.Request.Context())
if err != nil {
response.RecordError(c, err)
response.InternalServerError(c, "获取分类失败")
return
}
@@ -194,6 +198,7 @@ func (h *Handler) AdminListProducts(c *gin.Context) {
query.Page, query.PageSize = parsePagination(c)
result, err := h.service.AdminListProducts(c.Request.Context(), query)
if err != nil {
response.RecordError(c, err)
response.InternalServerError(c, "获取商品列表失败")
return
}
@@ -273,6 +278,7 @@ func (h *Handler) AdminListOrders(c *gin.Context) {
query.Page, query.PageSize = parsePagination(c)
result, err := h.service.AdminListOrders(c.Request.Context(), query)
if err != nil {
response.RecordError(c, err)
response.InternalServerError(c, "获取订单列表失败")
return
}
@@ -340,6 +346,7 @@ func (h *Handler) AdminCancelOrder(c *gin.Context) {
func (h *Handler) AdminGetConfig(c *gin.Context) {
item, err := h.service.GetConfig(c.Request.Context())
if err != nil {
response.RecordError(c, err)
response.InternalServerError(c, "获取配置失败")
return
}
@@ -354,6 +361,7 @@ func (h *Handler) AdminUpdateConfig(c *gin.Context) {
}
item, err := h.service.UpdateConfig(c.Request.Context(), req)
if err != nil {
response.RecordError(c, err)
response.InternalServerError(c, "更新配置失败")
return
}
@@ -361,6 +369,7 @@ func (h *Handler) AdminUpdateConfig(c *gin.Context) {
}
func writeError(c *gin.Context, err error) {
response.RecordError(c, err)
switch {
case errors.Is(err, ErrProductNotFound), errors.Is(err, ErrOrderNotFound):
response.NotFound(c, err.Error())