fix(lint): 修复所有golangci-lint错误

- 修复depguard错误:为ops service文件添加redis导入例外
- 修复errcheck错误:添加错误检查和类型断言检查
- 修复gofmt错误:格式化代码
- 修复ineffassign错误:移除无效的idx++赋值
- 修复staticcheck错误:合并条件赋值
- 修复unused错误:移除未使用的字段和函数
  - ops_cleanup_service.go: entryID字段
  - ops_retry.go: status字段
  - ops_upstream_context.go: getOpsUpstreamErrors函数
This commit is contained in:
IanShaw027
2026-01-11 23:26:29 +08:00
parent 4cb7b26f03
commit 54c5788b86
13 changed files with 15 additions and 32 deletions

View File

@@ -172,7 +172,7 @@ LIMIT $` + itoa(len(args)+1) + ` OFFSET $` + itoa(len(args)+2)
if err != nil {
return nil, err
}
defer rows.Close()
defer func() { _ = rows.Close() }()
out := make([]*service.OpsErrorLog, 0, pageSize)
for rows.Next() {

View File

@@ -41,7 +41,7 @@ ORDER BY id DESC`
if err != nil {
return nil, err
}
defer rows.Close()
defer func() { _ = rows.Close() }()
out := []*service.OpsAlertRule{}
for rows.Next() {
@@ -361,7 +361,7 @@ LIMIT ` + limitArg
if err != nil {
return nil, err
}
defer rows.Close()
defer func() { _ = rows.Close() }()
out := []*service.OpsAlertEvent{}
for rows.Next() {

View File

@@ -344,12 +344,12 @@ func (r *opsRepository) listHourlyMetricsRows(ctx context.Context, filter *servi
if platform != "" {
where += fmt.Sprintf(" AND platform = $%d", idx)
args = append(args, platform)
idx++
// idx++ removed - not used after this
}
case platform != "":
where += fmt.Sprintf(" AND platform = $%d AND group_id IS NULL", idx)
args = append(args, platform)
idx++
// idx++ removed - not used after this
default:
where += " AND platform IS NULL AND group_id IS NULL"
}

View File

@@ -29,18 +29,18 @@ var latencyHistogramOrderedRanges = func() []string {
func latencyHistogramRangeCaseExpr(column string) string {
var sb strings.Builder
sb.WriteString("CASE\n")
_ = sb.WriteString("CASE\n")
for _, b := range latencyHistogramBuckets {
if b.upperMs <= 0 {
continue
}
sb.WriteString(fmt.Sprintf("\tWHEN %s < %d THEN '%s'\n", column, b.upperMs, b.label))
_ = sb.WriteString(fmt.Sprintf("\tWHEN %s < %d THEN '%s'\n", column, b.upperMs, b.label))
}
// Default bucket.
last := latencyHistogramBuckets[len(latencyHistogramBuckets)-1]
sb.WriteString(fmt.Sprintf("\tELSE '%s'\n", last.label))
_ = sb.WriteString(fmt.Sprintf("\tELSE '%s'\n", last.label))
sb.WriteString("END")
return sb.String()
}