fix(lint): 修复 golangci-lint 检查问题

- 格式化代码 (gofmt)
- 修复 rows.Close() 返回值未检查 (errcheck)
- 删除未使用的 usage_clamp.go 文件 (unused)
- 删除临时测试目录
This commit is contained in:
ianshaw
2026-01-03 06:57:08 -08:00
parent 75e7c3dd06
commit 519b0b245a
7 changed files with 73 additions and 108 deletions

View File

@@ -1076,13 +1076,13 @@ func (s *GatewayService) Forward(ctx context.Context, c *gin.Context, account *A
}
// 处理错误响应(不可重试的错误)
if resp.StatusCode >= 400 {
// 可选:对部分 400 触发 failover默认关闭以保持语义
if resp.StatusCode == 400 && s.cfg != nil && s.cfg.Gateway.FailoverOn400 {
respBody, readErr := io.ReadAll(io.LimitReader(resp.Body, 2<<20))
if readErr != nil {
// ReadAll failed, fall back to normal error handling without consuming the stream
return s.handleErrorResponse(ctx, resp, c, account)
if resp.StatusCode >= 400 {
// 可选:对部分 400 触发 failover默认关闭以保持语义
if resp.StatusCode == 400 && s.cfg != nil && s.cfg.Gateway.FailoverOn400 {
respBody, readErr := io.ReadAll(io.LimitReader(resp.Body, 2<<20))
if readErr != nil {
// ReadAll failed, fall back to normal error handling without consuming the stream
return s.handleErrorResponse(ctx, resp, c, account)
}
_ = resp.Body.Close()
resp.Body = io.NopCloser(bytes.NewReader(respBody))

View File

@@ -1,35 +0,0 @@
package service
import "time"
// clampInt 将整数限制在指定范围内
func clampInt(value, min, max int) int {
if value < min {
return min
}
if value > max {
return max
}
return value
}
// clampFloat64 将浮点数限制在指定范围内
func clampFloat64(value, min, max float64) float64 {
if value < min {
return min
}
if value > max {
return max
}
return value
}
// remainingSecondsUntil 计算到指定时间的剩余秒数,保证非负
func remainingSecondsUntil(t time.Time) int {
seconds := int(time.Until(t).Seconds())
if seconds < 0 {
return 0
}
return seconds
}