refactor(idgen): centralize negative ID handling via panic

Restore NextUint64ID() to uint64-only API so callers need no error
checks. Retry logic stays in idgen; after 3 negative values it panics
instead of returning 0, preventing silent NULL primary keys.
This commit is contained in:
ryan
2026-06-17 13:14:17 +08:00
parent 92dc6a59c0
commit 3a05e7f09c
11 changed files with 17 additions and 68 deletions
+1 -8
View File
@@ -15,7 +15,6 @@ import (
"github.com/Rain-kl/Wavelet/internal/db/idgen"
"github.com/Rain-kl/Wavelet/internal/model"
"github.com/Rain-kl/Wavelet/internal/util"
"github.com/Rain-kl/Wavelet/pkg/logger"
"github.com/gin-gonic/gin"
)
@@ -70,14 +69,8 @@ func RiskControlMiddleware() gin.HandlerFunc {
status = maxHTTPStatus
}
logID, err := idgen.NextUint64ID()
if err != nil {
logger.ErrorF(c.Request.Context(), "[RiskControl] access log ID generation failed: %v", err)
return
}
logItem := &UserAccessLog{
ID: logID,
ID: idgen.NextUint64ID(),
UserID: userObj.ID, // 直接从 Context 获取已登录用户ID,避免数据库查询
Path: c.Request.URL.Path,
Method: c.Request.Method,