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:
@@ -235,32 +235,6 @@ func (s *UsageService) GetDailyStats(ctx context.Context, userID int64, days int
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
// calculateStats 计算统计数据
|
||||
func (s *UsageService) calculateStats(logs []UsageLog) *UsageStats {
|
||||
stats := &UsageStats{}
|
||||
|
||||
for _, log := range logs {
|
||||
stats.TotalRequests++
|
||||
stats.TotalInputTokens += int64(log.InputTokens)
|
||||
stats.TotalOutputTokens += int64(log.OutputTokens)
|
||||
stats.TotalCacheTokens += int64(log.CacheCreationTokens + log.CacheReadTokens)
|
||||
stats.TotalTokens += int64(log.TotalTokens())
|
||||
stats.TotalCost += log.TotalCost
|
||||
stats.TotalActualCost += log.ActualCost
|
||||
|
||||
if log.DurationMs != nil {
|
||||
stats.AverageDurationMs += float64(*log.DurationMs)
|
||||
}
|
||||
}
|
||||
|
||||
// 计算平均持续时间
|
||||
if stats.TotalRequests > 0 {
|
||||
stats.AverageDurationMs /= float64(stats.TotalRequests)
|
||||
}
|
||||
|
||||
return stats
|
||||
}
|
||||
|
||||
// Delete 删除使用日志(管理员功能,谨慎使用)
|
||||
func (s *UsageService) Delete(ctx context.Context, id int64) error {
|
||||
if err := s.usageRepo.Delete(ctx, id); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user