fix: resolve golangci-lint errors (gofmt alignment, errcheck)

- Fix gofmt: align struct field comments in UsageCache, trim trailing
  whitespace on const comments
- Fix errcheck: use comma-ok on type assertion for singleflight result

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
JIA-ss
2026-03-07 00:58:08 +08:00
parent 4ddedfaaf9
commit 1f3f9e131e

View File

@@ -98,8 +98,8 @@ type antigravityUsageCache struct {
const ( const (
apiCacheTTL = 3 * time.Minute apiCacheTTL = 3 * time.Minute
apiErrorCacheTTL = 1 * time.Minute // 负缓存 TTL429 等错误缓存 1 分钟,防止重试风暴 apiErrorCacheTTL = 1 * time.Minute // 负缓存 TTL429 等错误缓存 1 分钟
apiQueryMaxJitter = 800 * time.Millisecond // 用量查询最大随机延迟,打散并发请求避免反滥用检测 apiQueryMaxJitter = 800 * time.Millisecond // 用量查询最大随机延迟
windowStatsCacheTTL = 1 * time.Minute windowStatsCacheTTL = 1 * time.Minute
openAIProbeCacheTTL = 10 * time.Minute openAIProbeCacheTTL = 10 * time.Minute
openAICodexProbeVersion = "0.104.0" openAICodexProbeVersion = "0.104.0"
@@ -107,11 +107,11 @@ const (
// UsageCache 封装账户使用量相关的缓存 // UsageCache 封装账户使用量相关的缓存
type UsageCache struct { type UsageCache struct {
apiCache sync.Map // accountID -> *apiUsageCache apiCache sync.Map // accountID -> *apiUsageCache
windowStatsCache sync.Map // accountID -> *windowStatsCache windowStatsCache sync.Map // accountID -> *windowStatsCache
antigravityCache sync.Map // accountID -> *antigravityUsageCache antigravityCache sync.Map // accountID -> *antigravityUsageCache
apiFlight singleflight.Group // 防止同一账号的并发请求击穿缓存 apiFlight singleflight.Group // 防止同一账号的并发请求击穿缓存
openAIProbeCache sync.Map // accountID -> time.Time openAIProbeCache sync.Map // accountID -> time.Time
} }
// NewUsageCache 创建 UsageCache 实例 // NewUsageCache 创建 UsageCache 实例
@@ -326,7 +326,7 @@ func (s *AccountUsageService) GetUsage(ctx context.Context, accountID int64) (*U
if flightErr != nil { if flightErr != nil {
return nil, flightErr return nil, flightErr
} }
apiResp = result.(*ClaudeUsageResponse) apiResp, _ = result.(*ClaudeUsageResponse)
} }
// 3. 构建 UsageInfo每次都重新计算 RemainingSeconds // 3. 构建 UsageInfo每次都重新计算 RemainingSeconds