refactor: 错误消息脱敏 + 后端 CI

- 新增 utils.InternalMsg:内部错误详情只进服务端日志,对外统一脱敏
  消息,不再向客户端泄露 GORM/SQL 实现细节;九个 controller 的
  err.Error() 出口全部切换
- 新增 .github/workflows/ci.yml:go build/vet/test(backend,go 1.25)
This commit is contained in:
Logan.Li committed 2026-11-01 02:03:26 +08:00
1 parent 1a47dee63d
commit e0cef06234
11 files changed
+92 -49

No files matched your search

@@ -1,6 +1,8 @@
package license
import (
"backend/utils"
"backend/internal/dto"
"net/http"
@@ -27,7 +29,7 @@ func (ctrl *LicenseController) ActivateDevice(c *gin.Context) {
}
data, err := ctrl.svc.Activate(req, c.ClientIP())
if err != nil {
c.JSON(http.StatusOK, gin.H{"code": 1, "message": err.Error()})
c.JSON(http.StatusOK, gin.H{"code": 1, "message": utils.InternalMsg(err)})
return
}
c.JSON(http.StatusOK, gin.H{"code": 0, "message": "激活成功", "data": data})
@@ -41,7 +43,7 @@ func (ctrl *LicenseController) Deactivate(c *gin.Context) {
return
}
if err := ctrl.svc.Deactivate(req); err != nil {
c.JSON(http.StatusOK, gin.H{"code": 1, "message": err.Error()})
c.JSON(http.StatusOK, gin.H{"code": 1, "message": utils.InternalMsg(err)})
return
}
c.JSON(http.StatusOK, gin.H{"code": 0, "message": "停用成功"})
@@ -56,7 +58,7 @@ func (ctrl *LicenseController) Heartbeat(c *gin.Context) {
}
data, err := ctrl.svc.Heartbeat(req)
if err != nil {
c.JSON(http.StatusOK, gin.H{"code": 1, "message": err.Error()})
c.JSON(http.StatusOK, gin.H{"code": 1, "message": utils.InternalMsg(err)})
return
}
c.JSON(http.StatusOK, gin.H{"code": 0, "message": "心跳成功", "data": data})
@@ -73,7 +75,7 @@ func (ctrl *LicenseController) ListDevices(c *gin.Context) {
}
devices, maxDevices, err := ctrl.svc.ListDevicesByKey(req.LicenseKey)
if err != nil {
c.JSON(http.StatusOK, gin.H{"code": 1, "message": err.Error()})
c.JSON(http.StatusOK, gin.H{"code": 1, "message": utils.InternalMsg(err)})
return
}
c.JSON(http.StatusOK, gin.H{"code": 0, "data": gin.H{