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

- gofmt: 修复代码格式问题
- errcheck: 处理 WriteString 和 Close 返回值
- staticcheck: 错误信息改为小写开头
- staticcheck: 移除无效的 nil 检查
- staticcheck: 使用 append 替换循环
- staticcheck: 使用无条件的 TrimPrefix
- ineffassign: 移除无效赋值
- unused: 移除未使用的 geminiOAuthService 字段
- 重新生成 wire_gen.go
This commit is contained in:
ianshaw
2025-12-25 21:35:30 -08:00
parent 79d1585250
commit efa470efc7
9 changed files with 14 additions and 31 deletions

View File

@@ -445,13 +445,11 @@ func (s *PricingService) buildModelLookupCandidates(modelLower string) []string
normalizeModelNameForPricing(modelLower),
modelLower,
}
for _, cand := range []string{
candidates = append(candidates,
strings.TrimPrefix(modelLower, "models/"),
lastSegment(modelLower),
lastSegment(strings.TrimPrefix(modelLower, "models/")),
} {
candidates = append(candidates, cand)
}
)
seen := make(map[string]struct{}, len(candidates))
out := make([]string, 0, len(candidates))
@@ -479,13 +477,8 @@ func normalizeModelNameForPricing(model string) string {
// - projects/.../locations/.../publishers/google/models/gemini-1.5-pro
model = strings.TrimSpace(model)
model = strings.TrimLeft(model, "/")
if strings.HasPrefix(model, "models/") {
model = strings.TrimPrefix(model, "models/")
}
if strings.HasPrefix(model, "publishers/google/models/") {
model = strings.TrimPrefix(model, "publishers/google/models/")
}
model = strings.TrimPrefix(model, "models/")
model = strings.TrimPrefix(model, "publishers/google/models/")
if idx := strings.LastIndex(model, "/publishers/google/models/"); idx != -1 {
model = model[idx+len("/publishers/google/models/"):]