From 867fcb22887978ba0b0e64c9cd0ec1f67ba043cc Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 28 Aug 2026 16:53:32 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20revive=20cleanup=20=E2=80=94=20unus?= =?UTF-8?q?ed=20params=20to=20=5F,=20add=20missing=20doc=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - admin/db_helper GetCache/GetUserService/GetAuthService: ctx -> _ (签名对称保留) - validateMergedStorageConfig / ParseMigrationTargetConfig / MockStorageService.Put 未用参数 -> _ - SetDBServiceForTest、StorageDriver 常量组补充文档注释 lint_issues 33→26 --- .auto/log.jsonl | 1 + backend/core/contracts/storage.go | 1 + backend/plugins/domain/admin/db_helper.go | 15 +++++++++------ backend/plugins/domain/admin/handlers_config.go | 2 +- .../plugins/domain/message_gateway/db_helper.go | 1 + .../plugins/domain/upload/shared/test_helpers.go | 2 +- .../plugins/domain/upload/storage/migration.go | 2 +- 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.auto/log.jsonl b/.auto/log.jsonl index 3f5e4b86..a20a945d 100644 --- a/.auto/log.jsonl +++ b/.auto/log.jsonl @@ -1,2 +1,3 @@ {"ts":"2026-08-28T00:00:00Z","iter":0,"type":"baseline","metrics":{"lint_issues":45,"dup_issues":15,"tests_passed":44},"description":"baseline: 45 golangci issues (15 dupl), all tests pass","asi":{"note":"quick wins queue: gofumpt(4)+revive(8); then goconst/mnd; gosec; nilerr bug; contextcheck; dupl batches; nestif"}} {"ts":"2026-08-28","iter":1,"type":"keep","metrics":{"lint_issues":34,"dup_issues":15,"tests_passed":44},"delta":-11,"description":"goconst(9): taskCategoryUpload/taskQueueDefault consts in upload/task; reuse logDBNameSQLite in admin; mnd(1): defaultCleanupInterval in disk cache; staticcheck SA9004: split typed const group in asynq executor","asi":{"lesson":"golangci v2 defaults cap reporting at 50/3 - uncapped via issues:max-issues-per-linter/max-same-issues=0 (strict-only change); formatter war resolved: make format now = golangci-lint fmt (same gate as code-check), 203-file gofumpt normalization committed as infra"}} +{"ts":"2026-08-28","iter":2,"type":"keep","metrics":{"lint_issues":33,"dup_issues":15,"tests_passed":44},"delta":-1,"description":"nilerr real bug: FlushTaskExecutionLog swallowed cache faults (non-miss errors) and silently dropped buffered task logs; now propagates wrapped error, ErrCacheMiss stays a no-op. 3 regression tests (fault / miss / persist+clear) with miniredis + stubDBService(in-memory sqlite)","asi":{"lesson":"FlushTaskExecutionLog callers in executor.go only log errors, so returning wrapped err is safe; tests need SetDBService injection since testhelper.SetupTestEnvironment targets infra/database global not admin dbService"}} diff --git a/backend/core/contracts/storage.go b/backend/core/contracts/storage.go index b9618e63..81d43213 100644 --- a/backend/core/contracts/storage.go +++ b/backend/core/contracts/storage.go @@ -49,6 +49,7 @@ type IngestResult struct { // StorageDriver identifies a supported storage backend. type StorageDriver string +// Storage drivers supported by the platform. Values persist in storage configs. const ( StorageDriverLocal StorageDriver = "local" StorageDriverS3 StorageDriver = "s3" diff --git a/backend/plugins/domain/admin/db_helper.go b/backend/plugins/domain/admin/db_helper.go index 9d9c220b..928ff7a0 100644 --- a/backend/plugins/domain/admin/db_helper.go +++ b/backend/plugins/domain/admin/db_helper.go @@ -113,22 +113,25 @@ func GetDB(ctx context.Context) *gorm.DB { return dbService.DB(ctx) } -// GetCache returns the unified CacheService instance. -func GetCache(ctx context.Context) contracts.CacheService { +// GetCache returns the unified CacheService instance. ctx is kept for +// signature symmetry with the other context-aware accessors. +func GetCache(_ context.Context) contracts.CacheService { servicesMu.RLock() defer servicesMu.RUnlock() return cacheService } -// GetUserService returns the UserService instance. -func GetUserService(ctx context.Context) contracts.UserService { +// GetUserService returns the UserService instance. ctx is kept for +// signature symmetry with the other context-aware accessors. +func GetUserService(_ context.Context) contracts.UserService { servicesMu.RLock() defer servicesMu.RUnlock() return userService } -// GetAuthService returns the AuthService instance. -func GetAuthService(ctx context.Context) contracts.AuthService { +// GetAuthService returns the AuthService instance. ctx is kept for +// signature symmetry with the other context-aware accessors. +func GetAuthService(_ context.Context) contracts.AuthService { servicesMu.RLock() defer servicesMu.RUnlock() return authService diff --git a/backend/plugins/domain/admin/handlers_config.go b/backend/plugins/domain/admin/handlers_config.go index 81179785..6ce71d43 100644 --- a/backend/plugins/domain/admin/handlers_config.go +++ b/backend/plugins/domain/admin/handlers_config.go @@ -507,7 +507,7 @@ func validateAndMergeStorageConfig(ctx context.Context, value, currentConfig str return string(unmaskedVal), nil } -func validateMergedStorageConfig(ctx context.Context, currentCfg, newCfg, targetCfg contracts.StorageConfigDTO) error { +func validateMergedStorageConfig(ctx context.Context, currentCfg, newCfg, _ contracts.StorageConfigDTO) error { if newCfg.Driver != "" && newCfg.Driver != currentCfg.Driver { var uploadCount int64 gormDB := GetDB(ctx) diff --git a/backend/plugins/domain/message_gateway/db_helper.go b/backend/plugins/domain/message_gateway/db_helper.go index 9d1b5a83..eb7cef84 100644 --- a/backend/plugins/domain/message_gateway/db_helper.go +++ b/backend/plugins/domain/message_gateway/db_helper.go @@ -21,6 +21,7 @@ var ( taskSvc contracts.TaskService ) +// SetDBServiceForTest injects a DBService for tests. Production wiring must use Apply. func SetDBServiceForTest(s contracts.DBService) { setDBService(s) } diff --git a/backend/plugins/domain/upload/shared/test_helpers.go b/backend/plugins/domain/upload/shared/test_helpers.go index 1e00b815..d0132b5b 100644 --- a/backend/plugins/domain/upload/shared/test_helpers.go +++ b/backend/plugins/domain/upload/shared/test_helpers.go @@ -120,7 +120,7 @@ func NewMockStorageService() *MockStorageService { } // Put uploads an object into mock storage. -func (m *MockStorageService) Put(_ context.Context, key string, body io.Reader, size int64, contentType string) (contracts.StoragePutResult, error) { +func (m *MockStorageService) Put(_ context.Context, key string, body io.Reader, _ int64, contentType string) (contracts.StoragePutResult, error) { m.mu.Lock() defer m.mu.Unlock() data, err := io.ReadAll(body) diff --git a/backend/plugins/domain/upload/storage/migration.go b/backend/plugins/domain/upload/storage/migration.go index 0f813a5b..65a4aeda 100644 --- a/backend/plugins/domain/upload/storage/migration.go +++ b/backend/plugins/domain/upload/storage/migration.go @@ -36,7 +36,7 @@ func LatestMigrationExecution(ctx context.Context) (*contracts.TaskExecutionDTO, } // ParseMigrationTargetConfig parses and validates a storage migration target payload. -func ParseMigrationTargetConfig(ctx context.Context, payload []byte) (contracts.StorageConfigDTO, error) { +func ParseMigrationTargetConfig(_ context.Context, payload []byte) (contracts.StorageConfigDTO, error) { if strings.TrimSpace(string(payload)) == "" { return contracts.StorageConfigDTO{}, errors.New("storage migration target payload is required") }