mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-05 23:26:38 +08:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user