fix(lint): 修复 golangci-lint 检查错误

- 修复未检查的错误返回值 (errcheck)
- 移除未使用的 httpClient 字段 (unused)
- 修复低效赋值问题 (ineffassign)
- 使用 switch 替代 if-else 链 (staticcheck QF1003)
- 修复错误字符串首字母大写问题 (staticcheck ST1005)
- 运行 gofmt 格式化代码
This commit is contained in:
IanShaw027
2026-01-01 14:07:37 +08:00
parent 7df914af06
commit 34bbfb5dd2
3 changed files with 27 additions and 27 deletions

View File

@@ -22,17 +22,11 @@ type DriveClient interface {
GetStorageQuota(ctx context.Context, accessToken, proxyURL string) (*DriveStorageInfo, error)
}
type driveClient struct {
httpClient *http.Client
}
type driveClient struct{}
// NewDriveClient creates a new Drive API client
func NewDriveClient() DriveClient {
return &driveClient{
httpClient: &http.Client{
Timeout: 10 * time.Second,
},
}
return &driveClient{}
}
// GetStorageQuota fetches storage quota from Google Drive API
@@ -71,7 +65,7 @@ func (c *driveClient) GetStorageQuota(ctx context.Context, accessToken, proxyURL
// Rate limit - retry with exponential backoff
if resp.StatusCode == http.StatusTooManyRequests && attempt < maxRetries-1 {
resp.Body.Close()
_ = resp.Body.Close()
backoff := time.Duration(1<<uint(attempt)) * time.Second // 1s, 2s, 4s
time.Sleep(backoff)
continue
@@ -79,11 +73,11 @@ func (c *driveClient) GetStorageQuota(ctx context.Context, accessToken, proxyURL
// Other errors - return immediately
body, _ := io.ReadAll(resp.Body)
resp.Body.Close()
return nil, fmt.Errorf("Drive API error (status %d): %s", resp.StatusCode, string(body))
_ = resp.Body.Close()
return nil, fmt.Errorf("drive API error (status %d): %s", resp.StatusCode, string(body))
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
// Parse response
var result struct {
@@ -100,10 +94,10 @@ func (c *driveClient) GetStorageQuota(ctx context.Context, accessToken, proxyURL
// Parse limit and usage (handle both string and number formats)
var limit, usage int64
if result.StorageQuota.Limit != "" {
fmt.Sscanf(result.StorageQuota.Limit, "%d", &limit)
_, _ = fmt.Sscanf(result.StorageQuota.Limit, "%d", &limit)
}
if result.StorageQuota.Usage != "" {
fmt.Sscanf(result.StorageQuota.Usage, "%d", &usage)
_, _ = fmt.Sscanf(result.StorageQuota.Usage, "%d", &usage)
}
return &DriveStorageInfo{