From 9c88980483fabaca21ce41574a7355085ec73c3b Mon Sep 17 00:00:00 2001 From: IanShaw027 <131567472+IanShaw027@users.noreply.github.com> Date: Thu, 1 Jan 2026 04:26:01 +0800 Subject: [PATCH] =?UTF-8?q?fix(lint):=20=E4=BF=AE=E5=A4=8D=20golangci-lint?= =?UTF-8?q?=20=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 gofmt 格式问题 - 修复 staticcheck SA4031 nil check 问题(只在成功时设置 release 函数) - 删除未使用的 sortAccountsByPriority 函数 --- backend/internal/handler/gateway_handler.go | 16 ++++++++++------ .../internal/handler/gemini_v1beta_handler.go | 8 +++++--- backend/internal/pkg/antigravity/claude_types.go | 2 +- backend/internal/service/gateway_service.go | 6 ------ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/backend/internal/handler/gateway_handler.go b/backend/internal/handler/gateway_handler.go index 769e6700..70b42ffe 100644 --- a/backend/internal/handler/gateway_handler.go +++ b/backend/internal/handler/gateway_handler.go @@ -192,9 +192,11 @@ func (h *GatewayHandler) Messages(c *gin.Context) { log.Printf("Account wait queue full: account=%d", account.ID) h.handleStreamingAwareError(c, http.StatusTooManyRequests, "rate_limit_error", "Too many pending requests, please retry later", streamStarted) return - } - accountWaitRelease = func() { - h.concurrencyHelper.DecrementAccountWaitCount(c.Request.Context(), account.ID) + } else { + // Only set release function if increment succeeded + accountWaitRelease = func() { + h.concurrencyHelper.DecrementAccountWaitCount(c.Request.Context(), account.ID) + } } accountReleaseFunc, err = h.concurrencyHelper.AcquireAccountSlotWithWaitTimeout( @@ -314,9 +316,11 @@ func (h *GatewayHandler) Messages(c *gin.Context) { log.Printf("Account wait queue full: account=%d", account.ID) h.handleStreamingAwareError(c, http.StatusTooManyRequests, "rate_limit_error", "Too many pending requests, please retry later", streamStarted) return - } - accountWaitRelease = func() { - h.concurrencyHelper.DecrementAccountWaitCount(c.Request.Context(), account.ID) + } else { + // Only set release function if increment succeeded + accountWaitRelease = func() { + h.concurrencyHelper.DecrementAccountWaitCount(c.Request.Context(), account.ID) + } } accountReleaseFunc, err = h.concurrencyHelper.AcquireAccountSlotWithWaitTimeout( diff --git a/backend/internal/handler/gemini_v1beta_handler.go b/backend/internal/handler/gemini_v1beta_handler.go index 1959c0f3..93ab23c9 100644 --- a/backend/internal/handler/gemini_v1beta_handler.go +++ b/backend/internal/handler/gemini_v1beta_handler.go @@ -233,9 +233,11 @@ func (h *GatewayHandler) GeminiV1BetaModels(c *gin.Context) { log.Printf("Account wait queue full: account=%d", account.ID) googleError(c, http.StatusTooManyRequests, "Too many pending requests, please retry later") return - } - accountWaitRelease = func() { - geminiConcurrency.DecrementAccountWaitCount(c.Request.Context(), account.ID) + } else { + // Only set release function if increment succeeded + accountWaitRelease = func() { + geminiConcurrency.DecrementAccountWaitCount(c.Request.Context(), account.ID) + } } accountReleaseFunc, err = geminiConcurrency.AcquireAccountSlotWithWaitTimeout( diff --git a/backend/internal/pkg/antigravity/claude_types.go b/backend/internal/pkg/antigravity/claude_types.go index f394d7e3..01b805cd 100644 --- a/backend/internal/pkg/antigravity/claude_types.go +++ b/backend/internal/pkg/antigravity/claude_types.go @@ -41,7 +41,7 @@ type ClaudeMetadata struct { // 1. 标准格式: { "name": "...", "description": "...", "input_schema": {...} } // 2. Custom 格式 (MCP): { "type": "custom", "name": "...", "custom": { "description": "...", "input_schema": {...} } } type ClaudeTool struct { - Type string `json:"type,omitempty"` // "custom" 或空(标准格式) + Type string `json:"type,omitempty"` // "custom" 或空(标准格式) Name string `json:"name"` Description string `json:"description,omitempty"` // 标准格式使用 InputSchema map[string]any `json:"input_schema,omitempty"` // 标准格式使用 diff --git a/backend/internal/service/gateway_service.go b/backend/internal/service/gateway_service.go index 6c45ff0f..af9342b1 100644 --- a/backend/internal/service/gateway_service.go +++ b/backend/internal/service/gateway_service.go @@ -681,12 +681,6 @@ func (s *GatewayService) tryAcquireAccountSlot(ctx context.Context, accountID in return s.concurrencyService.AcquireAccountSlot(ctx, accountID, maxConcurrency) } -func sortAccountsByPriority(accounts []*Account) { - sort.SliceStable(accounts, func(i, j int) bool { - return accounts[i].Priority < accounts[j].Priority - }) -} - func sortAccountsByPriorityAndLastUsed(accounts []*Account, preferOAuth bool) { sort.SliceStable(accounts, func(i, j int) bool { a, b := accounts[i], accounts[j]