From 841d7ef2f23a4fae09c7613285ac3de551fff9e3 Mon Sep 17 00:00:00 2001 From: IanShaw027 <131567472+IanShaw027@users.noreply.github.com> Date: Wed, 14 Jan 2026 23:49:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(lint):=20=E4=BF=AE=E5=A4=8D=20golangci-lint?= =?UTF-8?q?=20=E6=A3=80=E6=9F=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 格式化代码(gofmt) - 修复空指针检查(staticcheck) - 删除未使用的函数(unused) --- backend/internal/handler/ops_error_logger.go | 1 - backend/internal/repository/ops_repo.go | 16 +++++++++------- backend/internal/service/ops_service.go | 8 -------- backend/internal/service/ops_settings_models.go | 14 +++++++------- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/backend/internal/handler/ops_error_logger.go b/backend/internal/handler/ops_error_logger.go index 2550771c..f62e6b3e 100644 --- a/backend/internal/handler/ops_error_logger.go +++ b/backend/internal/handler/ops_error_logger.go @@ -1013,4 +1013,3 @@ func shouldSkipOpsErrorLog(ctx context.Context, ops *service.OpsService, message return false } - diff --git a/backend/internal/repository/ops_repo.go b/backend/internal/repository/ops_repo.go index ef03dc8e..af957e34 100644 --- a/backend/internal/repository/ops_repo.go +++ b/backend/internal/repository/ops_repo.go @@ -967,13 +967,15 @@ func buildOpsErrorLogsWhere(filter *service.OpsErrorLogFilter) (string, []any) { args = append(args, phase) clauses = append(clauses, "error_phase = $"+itoa(len(args))) } - if owner := strings.TrimSpace(strings.ToLower(filter.Owner)); owner != "" { - args = append(args, owner) - clauses = append(clauses, "LOWER(COALESCE(error_owner,'')) = $"+itoa(len(args))) - } - if source := strings.TrimSpace(strings.ToLower(filter.Source)); source != "" { - args = append(args, source) - clauses = append(clauses, "LOWER(COALESCE(error_source,'')) = $"+itoa(len(args))) + if filter != nil { + if owner := strings.TrimSpace(strings.ToLower(filter.Owner)); owner != "" { + args = append(args, owner) + clauses = append(clauses, "LOWER(COALESCE(error_owner,'')) = $"+itoa(len(args))) + } + if source := strings.TrimSpace(strings.ToLower(filter.Source)); source != "" { + args = append(args, source) + clauses = append(clauses, "LOWER(COALESCE(error_source,'')) = $"+itoa(len(args))) + } } if resolvedFilter != nil { args = append(args, *resolvedFilter) diff --git a/backend/internal/service/ops_service.go b/backend/internal/service/ops_service.go index 915be5df..4c258652 100644 --- a/backend/internal/service/ops_service.go +++ b/backend/internal/service/ops_service.go @@ -612,11 +612,3 @@ func sanitizeErrorBodyForStorage(raw string, maxBytes int) (sanitized string, tr return raw, false } -func extractString(v any, key string) string { - root, ok := v.(map[string]any) - if !ok { - return "" - } - s, _ := root[key].(string) - return strings.TrimSpace(s) -} diff --git a/backend/internal/service/ops_settings_models.go b/backend/internal/service/ops_settings_models.go index 45280a81..df06f578 100644 --- a/backend/internal/service/ops_settings_models.go +++ b/backend/internal/service/ops_settings_models.go @@ -78,13 +78,13 @@ type OpsAlertRuntimeSettings struct { // OpsAdvancedSettings stores advanced ops configuration (data retention, aggregation). type OpsAdvancedSettings struct { - DataRetention OpsDataRetentionSettings `json:"data_retention"` - Aggregation OpsAggregationSettings `json:"aggregation"` - IgnoreCountTokensErrors bool `json:"ignore_count_tokens_errors"` - IgnoreContextCanceled bool `json:"ignore_context_canceled"` - IgnoreNoAvailableAccounts bool `json:"ignore_no_available_accounts"` - AutoRefreshEnabled bool `json:"auto_refresh_enabled"` - AutoRefreshIntervalSec int `json:"auto_refresh_interval_seconds"` + DataRetention OpsDataRetentionSettings `json:"data_retention"` + Aggregation OpsAggregationSettings `json:"aggregation"` + IgnoreCountTokensErrors bool `json:"ignore_count_tokens_errors"` + IgnoreContextCanceled bool `json:"ignore_context_canceled"` + IgnoreNoAvailableAccounts bool `json:"ignore_no_available_accounts"` + AutoRefreshEnabled bool `json:"auto_refresh_enabled"` + AutoRefreshIntervalSec int `json:"auto_refresh_interval_seconds"` } type OpsDataRetentionSettings struct {