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:
1 parent
1a47dee63d
commit
e0cef06234
11 files changed
+92
-49
No files matched your search
@@ -3,6 +3,8 @@
|
||||
package sync
|
||||
|
||||
import (
|
||||
|
||||
"backend/utils"
|
||||
"backend/config"
|
||||
"backend/internal/dto"
|
||||
"backend/internal/model"
|
||||
@@ -37,7 +39,7 @@ func (ctrl *Controller) Svc() *syncsvc.Service { return ctrl.svc }
|
||||
func (ctrl *Controller) ListPeers(c *gin.Context) {
|
||||
peers, err := ctrl.svc.ListPeers()
|
||||
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{
|
||||
@@ -54,7 +56,7 @@ func (ctrl *Controller) SavePeer(c *gin.Context) {
|
||||
}
|
||||
peer, err := ctrl.svc.SavePeer(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": peer})
|
||||
@@ -64,7 +66,7 @@ func (ctrl *Controller) SavePeer(c *gin.Context) {
|
||||
func (ctrl *Controller) DeletePeer(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 32)
|
||||
if err := ctrl.svc.DeletePeer(uint(id)); 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": "已删除"})
|
||||
@@ -75,7 +77,7 @@ func (ctrl *Controller) TestHandshake(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 32)
|
||||
peer, err := ctrl.svc.TestHandshake(uint(id))
|
||||
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": peer})
|
||||
@@ -91,7 +93,7 @@ func (ctrl *Controller) SyncNow(c *gin.Context) {
|
||||
}
|
||||
result, err := ctrl.svc.ExchangeOut(&peer)
|
||||
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": "同步完成: " + result})
|
||||
@@ -119,7 +121,7 @@ func (ctrl *Controller) HandshakeIn(c *gin.Context) {
|
||||
}
|
||||
resp, err := ctrl.svc.HandshakeIn(peer, req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"code": 1, "message": err.Error()})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"code": 1, "message": utils.InternalMsg(err)})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
@@ -138,7 +140,7 @@ func (ctrl *Controller) ExchangeIn(c *gin.Context) {
|
||||
}
|
||||
resp, err := ctrl.svc.ExchangeIn(peer, 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, resp)
|
||||
@@ -156,7 +158,7 @@ func (ctrl *Controller) readAndVerify(c *gin.Context) ([]byte, *model.PeerNode)
|
||||
return syncsvc.VerifySignature(p.SharedKey, c.Request, body)
|
||||
})
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"code": 1, "message": err.Error()})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"code": 1, "message": utils.InternalMsg(err)})
|
||||
return nil, nil
|
||||
}
|
||||
return body, peer
|
||||
|
||||
Reference in new issue
Block a user