fix(lint): 修复 golangci-lint 报告的代码问题

- errcheck: 修复类型断言未检查返回值的问题
  - pool.go: 添加 sync.Map 类型断言安全检查
  - req_client_pool.go: 添加 sync.Map 类型断言安全检查
  - concurrency_cache_benchmark_test.go: 显式忽略断言返回值
  - gateway_service.go: 显式忽略 WriteString 返回值

- gofmt: 修复代码格式问题
  - redis.go: 注释对齐
  - api_key_repo.go: 结构体字段对齐
  - concurrency_cache.go: 字段对齐
  - http_upstream.go: 注释对齐

- unused: 删除未使用的代码
  - user_repo.go: 删除未使用的 sql 字段
  - usage_service.go: 删除未使用的 calculateStats 函数

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
yangjianbo
2025-12-31 14:51:58 +08:00
parent dbc0cf33a1
commit 682f546c0e
10 changed files with 30 additions and 47 deletions

View File

@@ -311,13 +311,13 @@ func groupEntityToService(g *dbent.Group) *service.Group {
return nil
}
return &service.Group{
ID: g.ID,
Name: g.Name,
Description: derefString(g.Description),
Platform: g.Platform,
RateMultiplier: g.RateMultiplier,
IsExclusive: g.IsExclusive,
Status: g.Status,
ID: g.ID,
Name: g.Name,
Description: derefString(g.Description),
Platform: g.Platform,
RateMultiplier: g.RateMultiplier,
IsExclusive: g.IsExclusive,
Status: g.Status,
SubscriptionType: g.SubscriptionType,
DailyLimitUSD: g.DailyLimitUsd,
WeeklyLimitUSD: g.WeeklyLimitUsd,

View File

@@ -126,7 +126,7 @@ var (
)
type concurrencyCache struct {
rdb *redis.Client
rdb *redis.Client
slotTTLSeconds int // 槽位过期时间(秒)
}
@@ -137,7 +137,7 @@ func NewConcurrencyCache(rdb *redis.Client, slotTTLMinutes int) service.Concurre
slotTTLMinutes = defaultSlotTTLMinutes
}
return &concurrencyCache{
rdb: rdb,
rdb: rdb,
slotTTLSeconds: slotTTLMinutes * 60,
}
}

View File

@@ -22,7 +22,7 @@ func BenchmarkAccountConcurrency(b *testing.B) {
_ = rdb.Close()
}()
cache := NewConcurrencyCache(rdb, benchSlotTTLMinutes).(*concurrencyCache)
cache, _ := NewConcurrencyCache(rdb, benchSlotTTLMinutes).(*concurrencyCache)
ctx := context.Background()
for _, size := range []int{10, 100, 1000} {

View File

@@ -572,7 +572,7 @@ func buildUpstreamTransport(settings poolSettings, proxyURL *url.URL) *http.Tran
// trackedBody 带跟踪功能的响应体包装器
// 在 Close 时执行回调,用于更新请求计数
type trackedBody struct {
io.ReadCloser // 原始响应体
io.ReadCloser // 原始响应体
once sync.Once
onClose func() // 关闭时的回调函数
}

View File

@@ -35,7 +35,9 @@ var sharedReqClients sync.Map
func getSharedReqClient(opts reqClientOptions) *req.Client {
key := buildReqClientKey(opts)
if cached, ok := sharedReqClients.Load(key); ok {
return cached.(*req.Client)
if c, ok := cached.(*req.Client); ok {
return c
}
}
client := req.C().SetTimeout(opts.Timeout)
@@ -47,7 +49,10 @@ func getSharedReqClient(opts reqClientOptions) *req.Client {
}
actual, _ := sharedReqClients.LoadOrStore(key, client)
return actual.(*req.Client)
if c, ok := actual.(*req.Client); ok {
return c
}
return client
}
func buildReqClientKey(opts reqClientOptions) string {

View File

@@ -16,15 +16,14 @@ import (
type userRepository struct {
client *dbent.Client
sql sqlExecutor
}
func NewUserRepository(client *dbent.Client, sqlDB *sql.DB) service.UserRepository {
return newUserRepositoryWithSQL(client, sqlDB)
}
func newUserRepositoryWithSQL(client *dbent.Client, sqlq sqlExecutor) *userRepository {
return &userRepository{client: client, sql: sqlq}
func newUserRepositoryWithSQL(client *dbent.Client, _ sqlExecutor) *userRepository {
return &userRepository{client: client}
}
func (r *userRepository) Create(ctx context.Context, userIn *service.User) error {