diff --git a/.auto/log.jsonl b/.auto/log.jsonl new file mode 100644 index 00000000..56a4eeb3 --- /dev/null +++ b/.auto/log.jsonl @@ -0,0 +1 @@ +{"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"}} diff --git a/.golangci.yml b/.golangci.yml index 8536649e..f5009178 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -37,6 +37,7 @@ linters: dupl: threshold: 80 + cyclop: max-complexity: 20 package-average: 10 @@ -54,6 +55,12 @@ linters: - condition - return + +# 完整上报所有问题(取消 golangci 默认 50/3 截断,保证 code-check 与度量真实) +issues: + max-issues-per-linter: 0 + max-same-issues: 0 + formatters: enable: - gofumpt diff --git a/Makefile b/Makefile index 6bb9c6df..f0bd7f54 100644 --- a/Makefile +++ b/Makefile @@ -14,9 +14,8 @@ license-check: scripts/update_go_license.sh --check format: - @echo "==> Formatting backend Go source with goimports..." - @command -v goimports >/dev/null 2>&1 || { echo 'error: goimports is required. Run: go install golang.org/x/tools/cmd/goimports@latest' >&2; exit 1; } - goimports -w -local $(MODULE) $$(find backend -type f -name '*.go' -not -path './.git/*') + @echo "==> Formatting backend Go source with golangci-lint fmt (gofumpt, same gate as code-check)..." + cd backend && golangci-lint fmt @echo "==> Formatting frontend source..." cd frontend && pnpm format diff --git a/backend/cmd/all.go b/backend/cmd/all.go index 036fd2b8..0db6b9c4 100644 --- a/backend/cmd/all.go +++ b/backend/cmd/all.go @@ -5,11 +5,10 @@ package cmd import ( + "Wavelet/core" "log" "github.com/spf13/cobra" - - "Wavelet/core" ) var allCmd = &cobra.Command{ diff --git a/backend/cmd/api.go b/backend/cmd/api.go index e7130ffb..5209d552 100644 --- a/backend/cmd/api.go +++ b/backend/cmd/api.go @@ -4,11 +4,10 @@ package cmd import ( + "Wavelet/core" "log" "github.com/spf13/cobra" - - "Wavelet/core" ) var apiCmd = &cobra.Command{ diff --git a/backend/cmd/app.go b/backend/cmd/app.go index 4383fee3..81e8964a 100644 --- a/backend/cmd/app.go +++ b/backend/cmd/app.go @@ -4,17 +4,6 @@ package cmd import ( - "context" - "database/sql" - "fmt" - "io/fs" - "log" - "path/filepath" - "time" - - "github.com/pressly/goose/v3" - goosedb "github.com/pressly/goose/v3/database" - "Wavelet/core" "Wavelet/core/contracts" "Wavelet/pkg/config" @@ -33,9 +22,20 @@ import ( "Wavelet/plugins/drivers/driver_inproc_worker" "Wavelet/plugins/infra/cache" "Wavelet/plugins/infra/cache_memory" - infradb "Wavelet/plugins/infra/database" "Wavelet/plugins/infra/logger" "Wavelet/plugins/infra/storage" + "context" + "database/sql" + "fmt" + "io/fs" + "log" + "path/filepath" + "time" + + "github.com/pressly/goose/v3" + goosedb "github.com/pressly/goose/v3/database" + + infradb "Wavelet/plugins/infra/database" ) // newWaveletApp creates a core.App wired with Wavelet platform infrastructure, domain plugins, and profile drivers. diff --git a/backend/cmd/app_test.go b/backend/cmd/app_test.go index ed737fa8..89665419 100644 --- a/backend/cmd/app_test.go +++ b/backend/cmd/app_test.go @@ -4,13 +4,12 @@ package cmd import ( + "Wavelet/core" + "Wavelet/pkg/config" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/core" - "Wavelet/pkg/config" ) func TestNewWaveletAppProfiles(t *testing.T) { diff --git a/backend/cmd/banner.go b/backend/cmd/banner.go index 2a29be5e..21bde4ec 100644 --- a/backend/cmd/banner.go +++ b/backend/cmd/banner.go @@ -7,12 +7,11 @@ package cmd import ( + "Wavelet/pkg/buildinfo" + "Wavelet/pkg/config" "fmt" "runtime" "strings" - - "Wavelet/pkg/buildinfo" - "Wavelet/pkg/config" ) //nolint:unused // startup banner formatting utilities diff --git a/backend/cmd/banner_test.go b/backend/cmd/banner_test.go index 8bad1641..0faf4774 100644 --- a/backend/cmd/banner_test.go +++ b/backend/cmd/banner_test.go @@ -4,11 +4,10 @@ package cmd import ( - "strings" - "testing" - "Wavelet/pkg/buildinfo" "Wavelet/pkg/config" + "strings" + "testing" ) func TestFormatStartupBanner(t *testing.T) { diff --git a/backend/cmd/redis_plug_test.go b/backend/cmd/redis_plug_test.go index d4be231d..7c085866 100644 --- a/backend/cmd/redis_plug_test.go +++ b/backend/cmd/redis_plug_test.go @@ -4,6 +4,10 @@ package cmd import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/core/extpoints" + "Wavelet/pkg/config" "context" "fmt" "sync/atomic" @@ -12,11 +16,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/core/extpoints" - "Wavelet/pkg/config" ) func TestRedisPluggability_Simulation(t *testing.T) { diff --git a/backend/cmd/reset_passwd.go b/backend/cmd/reset_passwd.go index 51149ce7..00087de0 100644 --- a/backend/cmd/reset_passwd.go +++ b/backend/cmd/reset_passwd.go @@ -4,6 +4,8 @@ package cmd import ( + "Wavelet/plugins/domain/auth" + "Wavelet/plugins/infra/database" "bufio" "context" "crypto/rand" @@ -14,12 +16,9 @@ import ( "strings" userdomain "Wavelet/plugins/domain/user" - "Wavelet/plugins/infra/database" "github.com/spf13/cobra" "gorm.io/gorm" - - "Wavelet/plugins/domain/auth" ) var ( diff --git a/backend/cmd/reset_passwd_test.go b/backend/cmd/reset_passwd_test.go index b80370f7..0ad5b19b 100644 --- a/backend/cmd/reset_passwd_test.go +++ b/backend/cmd/reset_passwd_test.go @@ -4,13 +4,13 @@ package cmd import ( + "Wavelet/pkg/testhelper" "bytes" "io" "os" "testing" "time" - "Wavelet/pkg/testhelper" userdomain "Wavelet/plugins/domain/user" ) diff --git a/backend/cmd/root.go b/backend/cmd/root.go index 15afa4dd..cdc7dfd0 100644 --- a/backend/cmd/root.go +++ b/backend/cmd/root.go @@ -4,16 +4,15 @@ package cmd import ( + "Wavelet/pkg/buildinfo" + "Wavelet/pkg/config" + "Wavelet/pkg/logger" + "Wavelet/pkg/trace" "context" "log" "time" "github.com/spf13/cobra" - - "Wavelet/pkg/buildinfo" - "Wavelet/pkg/config" - "Wavelet/pkg/logger" - "Wavelet/pkg/trace" ) const traceShutdownTimeout = 10 * time.Second diff --git a/backend/cmd/scheduler.go b/backend/cmd/scheduler.go index 89e8dbb3..c3a499ad 100644 --- a/backend/cmd/scheduler.go +++ b/backend/cmd/scheduler.go @@ -4,11 +4,10 @@ package cmd import ( + "Wavelet/core" "log" "github.com/spf13/cobra" - - "Wavelet/core" ) var schedulerCmd = &cobra.Command{ diff --git a/backend/cmd/worker.go b/backend/cmd/worker.go index 83cd05e1..9c954a58 100644 --- a/backend/cmd/worker.go +++ b/backend/cmd/worker.go @@ -4,11 +4,10 @@ package cmd import ( + "Wavelet/core" "log" "github.com/spf13/cobra" - - "Wavelet/core" ) var workerCmd = &cobra.Command{ diff --git a/backend/core/app_test.go b/backend/core/app_test.go index 71aca568..4db66152 100644 --- a/backend/core/app_test.go +++ b/backend/core/app_test.go @@ -4,6 +4,8 @@ package core_test import ( + "Wavelet/core" + "Wavelet/core/extpoints" "context" "errors" "sync" @@ -13,9 +15,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/core" - "Wavelet/core/extpoints" ) // appMockDriver is a test driver tracking its start/stop lifecycle. diff --git a/backend/core/context.go b/backend/core/context.go index d7e69b87..617e860c 100644 --- a/backend/core/context.go +++ b/backend/core/context.go @@ -4,13 +4,12 @@ package core import ( + "Wavelet/core/extpoints" "context" "errors" "fmt" "sync" "time" - - "Wavelet/core/extpoints" ) // Context is the central micro-kernel service bus and runtime lifecycle container. @@ -103,7 +102,7 @@ func (c *Context) GoContext() context.Context { } // Set stores an arbitrary key-value pair in this Context's local storage. -func (c *Context) Set(key any, val any) { +func (c *Context) Set(key, val any) { c.mu.Lock() defer c.mu.Unlock() if c.values == nil { diff --git a/backend/core/context_test.go b/backend/core/context_test.go index 3b314312..56439fd9 100644 --- a/backend/core/context_test.go +++ b/backend/core/context_test.go @@ -4,6 +4,7 @@ package core_test import ( + "Wavelet/core" "context" "errors" "fmt" @@ -14,8 +15,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/core" ) // Sample services for testing diff --git a/backend/core/contracts/task.go b/backend/core/contracts/task.go index cd9a4e55..b61b8003 100644 --- a/backend/core/contracts/task.go +++ b/backend/core/contracts/task.go @@ -68,6 +68,6 @@ type TaskService interface { ValidatePayload(taskType string, payload []byte) ([]byte, error) ReloadScheduler() error AppendLog(ctx context.Context, format string, args ...any) - ListExecutions(ctx context.Context, taskType string, status string, page, pageSize int) ([]TaskExecutionDTO, int64, error) + ListExecutions(ctx context.Context, taskType, status string, page, pageSize int) ([]TaskExecutionDTO, int64, error) GetExecution(ctx context.Context, id uint64) (*TaskExecutionDTO, error) } diff --git a/backend/core/events.go b/backend/core/events.go index a47a4fbf..d30be096 100644 --- a/backend/core/events.go +++ b/backend/core/events.go @@ -14,8 +14,10 @@ import ( const maxHandlerParams = 2 -var ctxInterfaceType = reflect.TypeFor[context.Context]() -var errInterfaceType = reflect.TypeFor[error]() +var ( + ctxInterfaceType = reflect.TypeFor[context.Context]() + errInterfaceType = reflect.TypeFor[error]() +) type eventListener struct { id uint64 @@ -213,7 +215,6 @@ func (b *EventBus) Emit(ctx context.Context, topic string, payload any) error { } return resErr }() - if err != nil { errs = append(errs, err) } diff --git a/backend/core/events_test.go b/backend/core/events_test.go index 2c830f2d..730661fc 100644 --- a/backend/core/events_test.go +++ b/backend/core/events_test.go @@ -4,6 +4,7 @@ package core_test import ( + "Wavelet/core" "context" "errors" "fmt" @@ -13,8 +14,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/core" ) type UserRegisteredEvent struct { diff --git a/backend/core/extpoints/extpoints_test.go b/backend/core/extpoints/extpoints_test.go index 902ad816..1788b91a 100644 --- a/backend/core/extpoints/extpoints_test.go +++ b/backend/core/extpoints/extpoints_test.go @@ -4,6 +4,8 @@ package extpoints_test import ( + "Wavelet/core" + "Wavelet/core/extpoints" "context" "testing" "testing/fstest" @@ -11,9 +13,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/core" - "Wavelet/core/extpoints" ) func TestRouterExtension(t *testing.T) { diff --git a/backend/core/extpoints/router.go b/backend/core/extpoints/router.go index 8c18ac59..e73db66f 100644 --- a/backend/core/extpoints/router.go +++ b/backend/core/extpoints/router.go @@ -21,7 +21,7 @@ type RouteDefinition struct { type RouterExtension interface { Use(middlewares ...any) Group(prefix string, middlewares ...any) RouterExtension - Handle(method string, path string, handlers ...any) RouteDefinition + Handle(method, path string, handlers ...any) RouteDefinition GET(path string, handlers ...any) RouteDefinition POST(path string, handlers ...any) RouteDefinition PUT(path string, handlers ...any) RouteDefinition diff --git a/backend/core/extpoints/schedule.go b/backend/core/extpoints/schedule.go index de92f4d1..0c819041 100644 --- a/backend/core/extpoints/schedule.go +++ b/backend/core/extpoints/schedule.go @@ -28,8 +28,8 @@ func WithScheduleOption(key string, val any) ScheduleOption { // ScheduleExtension defines the interface for registering and querying cron/scheduled tasks. type ScheduleExtension interface { - Register(spec string, taskType string, payload any, opts ...ScheduleOption) - RegisterCron(spec string, taskType string, payload any, opts ...ScheduleOption) + Register(spec, taskType string, payload any, opts ...ScheduleOption) + RegisterCron(spec, taskType string, payload any, opts ...ScheduleOption) Schedules() []ScheduleDefinition Get(taskType string) (ScheduleDefinition, bool) Unregister(taskType string) bool @@ -50,7 +50,7 @@ func NewScheduleRegistry() *ScheduleRegistry { } // Register adds a schedule definition. -func (s *ScheduleRegistry) Register(spec string, taskType string, payload any, opts ...ScheduleOption) { +func (s *ScheduleRegistry) Register(spec, taskType string, payload any, opts ...ScheduleOption) { s.mu.Lock() defer s.mu.Unlock() @@ -82,7 +82,7 @@ func (s *ScheduleRegistry) Register(spec string, taskType string, payload any, o } // RegisterCron is an alias for Register. -func (s *ScheduleRegistry) RegisterCron(spec string, taskType string, payload any, opts ...ScheduleOption) { +func (s *ScheduleRegistry) RegisterCron(spec, taskType string, payload any, opts ...ScheduleOption) { s.Register(spec, taskType, payload, opts...) } diff --git a/backend/core/fiber_test.go b/backend/core/fiber_test.go index 091cbca9..b37e6ab7 100644 --- a/backend/core/fiber_test.go +++ b/backend/core/fiber_test.go @@ -4,14 +4,13 @@ package core_test import ( + "Wavelet/core" "context" "reflect" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/core" ) type MockServiceA interface { diff --git a/backend/core/scoped_extpoints.go b/backend/core/scoped_extpoints.go index 9edeee24..5db27401 100644 --- a/backend/core/scoped_extpoints.go +++ b/backend/core/scoped_extpoints.go @@ -30,7 +30,7 @@ func (s *scopedRouterExtension) Group(prefix string, middlewares ...any) extpoin return newScopedRouterExtension(s.ctx, subGroup) } -func (s *scopedRouterExtension) Handle(method string, path string, handlers ...any) extpoints.RouteDefinition { +func (s *scopedRouterExtension) Handle(method, path string, handlers ...any) extpoints.RouteDefinition { rd := s.underlying.Handle(method, path, handlers...) routeID := rd.ID s.ctx.OnDispose(func() error { @@ -141,7 +141,7 @@ func newScopedScheduleExtension(ctx *Context, underlying extpoints.ScheduleExten } } -func (s *scopedScheduleExtension) Register(spec string, taskType string, payload any, opts ...extpoints.ScheduleOption) { +func (s *scopedScheduleExtension) Register(spec, taskType string, payload any, opts ...extpoints.ScheduleOption) { s.underlying.Register(spec, taskType, payload, opts...) s.ctx.OnDispose(func() error { s.underlying.Unregister(taskType) @@ -149,7 +149,7 @@ func (s *scopedScheduleExtension) Register(spec string, taskType string, payload }) } -func (s *scopedScheduleExtension) RegisterCron(spec string, taskType string, payload any, opts ...extpoints.ScheduleOption) { +func (s *scopedScheduleExtension) RegisterCron(spec, taskType string, payload any, opts ...extpoints.ScheduleOption) { s.Register(spec, taskType, payload, opts...) } diff --git a/backend/core/types.go b/backend/core/types.go index cb403888..f8baae9d 100644 --- a/backend/core/types.go +++ b/backend/core/types.go @@ -4,11 +4,10 @@ package core import ( + "Wavelet/core/extpoints" "context" "errors" "reflect" - - "Wavelet/core/extpoints" ) // Standard sentinel errors returned by core operations. diff --git a/backend/downstream/plugins/custom_example/plugin.go b/backend/downstream/plugins/custom_example/plugin.go index bf5465bb..103842b6 100644 --- a/backend/downstream/plugins/custom_example/plugin.go +++ b/backend/downstream/plugins/custom_example/plugin.go @@ -6,12 +6,11 @@ package custom_example import ( + "Wavelet/core" + "Wavelet/core/contracts" "net/http" "github.com/gin-gonic/gin" - - "Wavelet/core" - "Wavelet/core/contracts" ) // Plugin implements core.Plugin for the custom_example downstream plugin. diff --git a/backend/pkg/batchwriter/writer.go b/backend/pkg/batchwriter/writer.go index c460ef6a..431bbd69 100644 --- a/backend/pkg/batchwriter/writer.go +++ b/backend/pkg/batchwriter/writer.go @@ -242,7 +242,7 @@ func (w *Writer[T]) run() { } } -func (w *Writer[T]) shouldFlushOnInterval(batchLen int, batchStartedAt time.Time, now time.Time) bool { +func (w *Writer[T]) shouldFlushOnInterval(batchLen int, batchStartedAt, now time.Time) bool { if batchLen == 0 { return false } diff --git a/backend/pkg/cache/disk/cache.go b/backend/pkg/cache/disk/cache.go index 210542a4..54de11f3 100644 --- a/backend/pkg/cache/disk/cache.go +++ b/backend/pkg/cache/disk/cache.go @@ -26,7 +26,7 @@ const ( headerSize = 8 // 8 bytes metadata prefix for expiration UnixNano timestamp defaultMaxSizeMB = 100 defaultTTLMinutes = 60 - cacheDirPerm = 0750 + cacheDirPerm = 0o750 // DefaultExpiration applies the cache-wide default TTL. DefaultExpiration time.Duration = 0 @@ -284,7 +284,7 @@ func (c *Cache) Status() Status { } // UpdatePolicy dynamically updates policies. -func (c *Cache) UpdatePolicy(maxSizeMB int64, ttlMinutes int64, lruEnabled bool) { +func (c *Cache) UpdatePolicy(maxSizeMB, ttlMinutes int64, lruEnabled bool) { c.mu.Lock() defer c.mu.Unlock() diff --git a/backend/pkg/cache/ram/manager.go b/backend/pkg/cache/ram/manager.go index 1198a70a..f316d88d 100644 --- a/backend/pkg/cache/ram/manager.go +++ b/backend/pkg/cache/ram/manager.go @@ -31,7 +31,7 @@ type CacheItem struct { // Loader is an interface that the cache client must implement to handle database retrieval. type Loader interface { LoadAll(ctx context.Context, configType string) ([]CacheItem, error) - LoadOne(ctx context.Context, configType string, key string) (CacheItem, error) + LoadOne(ctx context.Context, configType, key string) (CacheItem, error) } type cacheEntry struct { @@ -59,7 +59,7 @@ func getWriteLock(configType string) *sync.Mutex { // Get retrieves a cache item from the local cache store, checking for expiration. // Reads are completely lock-free because maps stored in Otter are immutable. -func Get(configType string, key string) (CacheItem, bool) { +func Get(configType, key string) (CacheItem, bool) { m, ok := managerCache.GetIfPresent(configType) if !ok { return CacheItem{}, false @@ -80,7 +80,7 @@ func Get(configType string, key string) (CacheItem, bool) { return entry.item, true } -func deleteKeyIfExpired(configType string, key string, expireAt time.Time) { +func deleteKeyIfExpired(configType, key string, expireAt time.Time) { lock := getWriteLock(configType) lock.Lock() defer lock.Unlock() @@ -138,7 +138,7 @@ func Set(item CacheItem) { // Delete removes a single item from the local cache store. // Writes are protected by a fine-grained lock per configType. -func Delete(configType string, key string) { +func Delete(configType, key string) { lock := getWriteLock(configType) lock.Lock() defer lock.Unlock() @@ -196,7 +196,7 @@ func GetTypeItems(configType string) []CacheItem { } // Refresh reloads configuration cache from database via the Loader. -func Refresh(ctx context.Context, configType string, key string, loader Loader) error { +func Refresh(ctx context.Context, configType, key string, loader Loader) error { if configType == "" { return errors.New("type is required") } diff --git a/backend/pkg/config/model.go b/backend/pkg/config/model.go index 1b925973..91321943 100644 --- a/backend/pkg/config/model.go +++ b/backend/pkg/config/model.go @@ -118,8 +118,7 @@ type logConfig struct { } // schedulerConfig 定时任务配置 -type schedulerConfig struct { -} +type schedulerConfig struct{} // workerConfig 工作配置 type workerConfig struct { diff --git a/backend/pkg/httppool/httppool_test.go b/backend/pkg/httppool/httppool_test.go index a753bda7..edaec191 100644 --- a/backend/pkg/httppool/httppool_test.go +++ b/backend/pkg/httppool/httppool_test.go @@ -52,7 +52,7 @@ func TestNewTransportUsesConfiguredDirectDialer(t *testing.T) { dialer := &net.Dialer{} transport := NewTransport(TransportOptions{ Proxy: nil, - DialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { + DialContext: func(ctx context.Context, network, address string) (net.Conn, error) { dialedAddress = address return dialer.DialContext(ctx, network, server.Listener.Addr().String()) }, diff --git a/backend/pkg/idgen/snowflake.go b/backend/pkg/idgen/snowflake.go index 50a45d6e..8e01c11c 100644 --- a/backend/pkg/idgen/snowflake.go +++ b/backend/pkg/idgen/snowflake.go @@ -5,12 +5,11 @@ package idgen import ( + "Wavelet/pkg/config" "fmt" "log" "github.com/bwmarrin/snowflake" - - "Wavelet/pkg/config" ) // 2025-12-01 00:00:00 UTC 的毫秒时间戳 diff --git a/backend/pkg/logger/ringbuffer.go b/backend/pkg/logger/ringbuffer.go index 27b0d8cc..5053b880 100644 --- a/backend/pkg/logger/ringbuffer.go +++ b/backend/pkg/logger/ringbuffer.go @@ -99,7 +99,7 @@ func (r *LogRingBuffer) appendLine(line string) { // cursor=0 表示查询最新日志,cursor>0 表示查询 index < cursor 的更早日志 // limit 为返回条数上限 // 返回日志条目(按 index 升序)和是否有更早的日志 -func (r *LogRingBuffer) Query(cursor int, limit int) ([]LogEntry, bool) { +func (r *LogRingBuffer) Query(cursor, limit int) ([]LogEntry, bool) { r.mu.RLock() defer r.mu.RUnlock() diff --git a/backend/pkg/logger/utils.go b/backend/pkg/logger/utils.go index 4f7741ea..37e12c92 100644 --- a/backend/pkg/logger/utils.go +++ b/backend/pkg/logger/utils.go @@ -17,7 +17,7 @@ import ( ) // logDirPerm 日志目录权限 -const logDirPerm = 0750 +const logDirPerm = 0o750 func getLogWriterForConfig(cfg Config) (zapcore.WriteSyncer, error) { if cfg.Output == "file" { diff --git a/backend/pkg/mail/mail.go b/backend/pkg/mail/mail.go index b4ce1929..b64ae5fe 100644 --- a/backend/pkg/mail/mail.go +++ b/backend/pkg/mail/mail.go @@ -38,12 +38,12 @@ func sanitizeHeaderValue(v string) string { } // SendMail sends an HTML email using the provided config and message details -func SendMail(ctx context.Context, cfg Config, to string, subject, body string) error { +func SendMail(ctx context.Context, cfg Config, to, subject, body string) error { return SendMailHTML(ctx, cfg, to, subject, body) } // SendMailHTML sends an HTML format email -func SendMailHTML(ctx context.Context, cfg Config, to string, subject, body string) error { +func SendMailHTML(ctx context.Context, cfg Config, to, subject, body string) error { addr := net.JoinHostPort(cfg.Host, strconv.Itoa(cfg.Port)) // Header & MIME settings for HTML email @@ -124,9 +124,9 @@ func sendMailViaSSL(ctx context.Context, addr string, auth smtp.Auth, cfg Config } // SendMailWithLog sends a test email and records a detailed SMTP connection log -func SendMailWithLog(ctx context.Context, cfg Config, to string, subject, body string) (string, error) { +func SendMailWithLog(ctx context.Context, cfg Config, to, subject, body string) (string, error) { var logBuf bytes.Buffer - logLine := func(dir string, format string, args ...interface{}) { + logLine := func(dir, format string, args ...interface{}) { fmt.Fprintf(&logBuf, "[%s] %s\n", dir, fmt.Sprintf(format, args...)) } diff --git a/backend/pkg/testhelper/gin.go b/backend/pkg/testhelper/gin.go index 08ed0f14..29b8c19f 100644 --- a/backend/pkg/testhelper/gin.go +++ b/backend/pkg/testhelper/gin.go @@ -4,9 +4,9 @@ package testhelper import ( - "github.com/gin-gonic/gin" - "Wavelet/pkg/response" + + "github.com/gin-gonic/gin" ) // NewTestGinEngine 创建带 ErrorHandlerMiddleware 的 Gin 引擎,与生产环境错误响应行为一致。 diff --git a/backend/pkg/trace/trace.go b/backend/pkg/trace/trace.go index 7d64ec7d..0e5bf0b1 100644 --- a/backend/pkg/trace/trace.go +++ b/backend/pkg/trace/trace.go @@ -12,8 +12,10 @@ import ( ) // Tracer 全局 OpenTelemetry Tracer 实例 -var Tracer trace.Tracer -var shutdownFuncs []func(context.Context) error +var ( + Tracer trace.Tracer + shutdownFuncs []func(context.Context) error +) func init() { // 初始化 Propagator diff --git a/backend/pkg/util/crypto.go b/backend/pkg/util/crypto.go index 94bd99c5..4f2ad19a 100644 --- a/backend/pkg/util/crypto.go +++ b/backend/pkg/util/crypto.go @@ -33,7 +33,7 @@ const ( // signKey: 64 字符 hex 编码的密钥(对应 32 字节,用于 AES-256) // plaintext: 要加密的明文字符串 // return: base64 编码的密文 -func Encrypt(signKey string, plaintext string) (string, error) { +func Encrypt(signKey, plaintext string) (string, error) { return encryptBytes(signKey, []byte(plaintext)) } @@ -41,7 +41,7 @@ func Encrypt(signKey string, plaintext string) (string, error) { // signKey: 64 字符 hex 编码的密钥(对应 32 字节,用于 AES-256) // ciphertext: base64 编码的密文 // return: 解密后的明文字符串 -func Decrypt(signKey string, ciphertext string) (string, error) { +func Decrypt(signKey, ciphertext string) (string, error) { plaintext, err := decryptBytes(signKey, ciphertext) if err != nil { return "", err @@ -86,7 +86,7 @@ func encryptBytes(signKey string, plaintext []byte) (string, error) { } // decryptBytes 解密函数,处理字节数据 -func decryptBytes(signKey string, ciphertext string) ([]byte, error) { +func decryptBytes(signKey, ciphertext string) ([]byte, error) { // 将 hex 编码的密钥转换为字节 key, err := hex.DecodeString(signKey) if err != nil { diff --git a/backend/pkg/util/http_clients.go b/backend/pkg/util/http_clients.go index e9bff60c..e8eed7a8 100644 --- a/backend/pkg/util/http_clients.go +++ b/backend/pkg/util/http_clients.go @@ -4,14 +4,13 @@ package util import ( + "Wavelet/pkg/httppool" "context" "fmt" "io" "net/http" "net/url" "time" - - "Wavelet/pkg/httppool" ) // IsLocalhost 检查 URL 是否为 localhost diff --git a/backend/pkg/util/password.go b/backend/pkg/util/password.go index 84060e37..55f5e97a 100644 --- a/backend/pkg/util/password.go +++ b/backend/pkg/util/password.go @@ -18,8 +18,10 @@ func HashPassword(password string) (string, error) { return string(hash), nil } -var dummyPasswordHashOnce sync.Once -var dummyPasswordHash string +var ( + dummyPasswordHashOnce sync.Once + dummyPasswordHash string +) func dummyHash() string { dummyPasswordHashOnce.Do(func() { diff --git a/backend/plugins/domain/admin/db_helper.go b/backend/plugins/domain/admin/db_helper.go index 248b5d40..9d9c220b 100644 --- a/backend/plugins/domain/admin/db_helper.go +++ b/backend/plugins/domain/admin/db_helper.go @@ -4,12 +4,11 @@ package admin import ( + "Wavelet/core/contracts" "context" "sync" "gorm.io/gorm" - - "Wavelet/core/contracts" ) var ( diff --git a/backend/plugins/domain/admin/handlers_auth_source.go b/backend/plugins/domain/admin/handlers_auth_source.go index 49d610b4..179c604b 100644 --- a/backend/plugins/domain/admin/handlers_auth_source.go +++ b/backend/plugins/domain/admin/handlers_auth_source.go @@ -4,13 +4,12 @@ package admin import ( + "Wavelet/core/contracts" + "Wavelet/pkg/response" "net/http" "strconv" "github.com/gin-gonic/gin" - - "Wavelet/core/contracts" - "Wavelet/pkg/response" ) // ListAuthSources lists all configured authentication sources. diff --git a/backend/plugins/domain/admin/handlers_cache.go b/backend/plugins/domain/admin/handlers_cache.go index 7e0f8404..5479ff54 100644 --- a/backend/plugins/domain/admin/handlers_cache.go +++ b/backend/plugins/domain/admin/handlers_cache.go @@ -4,6 +4,7 @@ package admin import ( + "Wavelet/pkg/response" "context" "net/http" "strconv" @@ -11,7 +12,6 @@ import ( "github.com/gin-gonic/gin" pkgcache "Wavelet/pkg/cache/disk" - "Wavelet/pkg/response" ) type updateCacheConfigRequest struct { diff --git a/backend/plugins/domain/admin/handlers_config.go b/backend/plugins/domain/admin/handlers_config.go index e2bd2bfe..81179785 100644 --- a/backend/plugins/domain/admin/handlers_config.go +++ b/backend/plugins/domain/admin/handlers_config.go @@ -4,6 +4,9 @@ package admin import ( + "Wavelet/core/contracts" + "Wavelet/pkg/logger" + "Wavelet/pkg/response" "context" "encoding/json" "errors" @@ -15,10 +18,7 @@ import ( "github.com/gin-gonic/gin" "gorm.io/gorm" - "Wavelet/core/contracts" - "Wavelet/pkg/logger" mail "Wavelet/pkg/mail" - "Wavelet/pkg/response" ) const maskedConfigValue = "******" @@ -465,7 +465,7 @@ func maskSensitiveConfig(key, value string) string { // validateAndMergeStorageConfig parses, merges unmasked secrets, validates parameter values, // and tests connectivity of the new storage configuration. -func validateAndMergeStorageConfig(ctx context.Context, value string, currentConfig string) (string, error) { +func validateAndMergeStorageConfig(ctx context.Context, value, currentConfig string) (string, error) { var currentCfg contracts.StorageConfigDTO if err := json.Unmarshal([]byte(currentConfig), ¤tCfg); err != nil { return "", fmt.Errorf("解析当前存储配置失败: %w", err) diff --git a/backend/plugins/domain/admin/handlers_db.go b/backend/plugins/domain/admin/handlers_db.go index 2fee530c..b17581f8 100644 --- a/backend/plugins/domain/admin/handlers_db.go +++ b/backend/plugins/domain/admin/handlers_db.go @@ -4,6 +4,8 @@ package admin import ( + "Wavelet/pkg/config" + "Wavelet/pkg/response" "context" "database/sql" "fmt" @@ -17,9 +19,6 @@ import ( "github.com/gin-gonic/gin" "gorm.io/gorm" - - "Wavelet/pkg/config" - "Wavelet/pkg/response" ) const ( diff --git a/backend/plugins/domain/admin/handlers_logs.go b/backend/plugins/domain/admin/handlers_logs.go index b6e64775..c4a7a551 100644 --- a/backend/plugins/domain/admin/handlers_logs.go +++ b/backend/plugins/domain/admin/handlers_logs.go @@ -4,6 +4,11 @@ package admin import ( + "Wavelet/core/contracts" + "Wavelet/pkg/config" + "Wavelet/pkg/logger" + "Wavelet/pkg/response" + "Wavelet/pkg/util" "context" "encoding/json" "errors" @@ -16,12 +21,6 @@ import ( "github.com/gin-gonic/gin" "github.com/gorilla/websocket" - - "Wavelet/core/contracts" - "Wavelet/pkg/config" - "Wavelet/pkg/logger" - "Wavelet/pkg/response" - "Wavelet/pkg/util" ) const ( diff --git a/backend/plugins/domain/admin/handlers_status.go b/backend/plugins/domain/admin/handlers_status.go index b87015a9..c7a8b1b3 100644 --- a/backend/plugins/domain/admin/handlers_status.go +++ b/backend/plugins/domain/admin/handlers_status.go @@ -4,6 +4,9 @@ package admin import ( + "Wavelet/pkg/config" + "Wavelet/pkg/logger" + "Wavelet/pkg/response" "context" "errors" "fmt" @@ -14,10 +17,6 @@ import ( "github.com/gin-gonic/gin" "gorm.io/gorm" - - "Wavelet/pkg/config" - "Wavelet/pkg/logger" - "Wavelet/pkg/response" ) var startTime = time.Now() diff --git a/backend/plugins/domain/admin/handlers_tasks.go b/backend/plugins/domain/admin/handlers_tasks.go index 608c72a7..111af920 100644 --- a/backend/plugins/domain/admin/handlers_tasks.go +++ b/backend/plugins/domain/admin/handlers_tasks.go @@ -4,6 +4,9 @@ package admin import ( + "Wavelet/core/contracts" + "Wavelet/pkg/logger" + "Wavelet/pkg/response" "fmt" "net/http" "strconv" @@ -12,10 +15,6 @@ import ( "github.com/gin-gonic/gin" "github.com/robfig/cron/v3" - - "Wavelet/core/contracts" - "Wavelet/pkg/logger" - "Wavelet/pkg/response" ) // ListTaskTypes 获取支持的任务类型列表 diff --git a/backend/plugins/domain/admin/handlers_templates.go b/backend/plugins/domain/admin/handlers_templates.go index 0a2bfc0e..9d6af375 100644 --- a/backend/plugins/domain/admin/handlers_templates.go +++ b/backend/plugins/domain/admin/handlers_templates.go @@ -4,14 +4,13 @@ package admin import ( + "Wavelet/pkg/response" "context" "errors" "net/http" "github.com/gin-gonic/gin" "gorm.io/gorm" - - "Wavelet/pkg/response" ) // CreateTemplateRequest 创建模板请求 diff --git a/backend/plugins/domain/admin/handlers_updater.go b/backend/plugins/domain/admin/handlers_updater.go index 681c7ea8..f645ad05 100644 --- a/backend/plugins/domain/admin/handlers_updater.go +++ b/backend/plugins/domain/admin/handlers_updater.go @@ -4,6 +4,10 @@ package admin import ( + "Wavelet/pkg/buildinfo" + "Wavelet/pkg/logger" + "Wavelet/pkg/response" + "Wavelet/pkg/util" "archive/tar" "archive/zip" "compress/gzip" @@ -23,11 +27,6 @@ import ( "github.com/gin-gonic/gin" "golang.org/x/mod/semver" - - "Wavelet/pkg/buildinfo" - "Wavelet/pkg/logger" - "Wavelet/pkg/response" - "Wavelet/pkg/util" ) const ( @@ -391,7 +390,7 @@ func matchBinaryName(name string, candidates []string) bool { return false } -func getCandidateBinaryNames(executable string, repository string) []string { +func getCandidateBinaryNames(executable, repository string) []string { execName := filepath.Base(executable) names := []string{execName} @@ -435,7 +434,7 @@ func isLikelyBinary(name string, isDir bool, mode os.FileMode) bool { return filepath.Ext(base) == ".exe" } - return (mode.Perm()&0111 != 0) || (filepath.Ext(base) == "") + return (mode.Perm()&0o111 != 0) || (filepath.Ext(base) == "") } func findBinaryInTarGz(archivePath string, candidates []string) (string, error) { diff --git a/backend/plugins/domain/admin/handlers_user.go b/backend/plugins/domain/admin/handlers_user.go index cef3b36c..db954242 100644 --- a/backend/plugins/domain/admin/handlers_user.go +++ b/backend/plugins/domain/admin/handlers_user.go @@ -4,6 +4,10 @@ package admin import ( + "Wavelet/core/contracts" + "Wavelet/pkg/logger" + "Wavelet/pkg/response" + "Wavelet/pkg/util" "errors" "net/http" "strconv" @@ -11,11 +15,6 @@ import ( "github.com/gin-gonic/gin" "gorm.io/gorm" - - "Wavelet/core/contracts" - "Wavelet/pkg/logger" - "Wavelet/pkg/response" - "Wavelet/pkg/util" ) // listUsersRequest 用户列表查询请求 @@ -393,7 +392,6 @@ func UpdateUser(c *gin.Context) { IsAdmin: req.IsAdmin, Password: req.Password, }) - if err != nil { if abortUserLogicError(c, err, userNotFound, []string{cannotRevokeSelfAdmin}, []string{emailRequired, emailExists, passwordTooShort}) { return diff --git a/backend/plugins/domain/admin/middlewares.go b/backend/plugins/domain/admin/middlewares.go index e244ff9d..9632c7aa 100644 --- a/backend/plugins/domain/admin/middlewares.go +++ b/backend/plugins/domain/admin/middlewares.go @@ -4,13 +4,13 @@ package admin import ( - "github.com/gin-gonic/gin" - "Wavelet/core/contracts" "Wavelet/pkg/logger" "Wavelet/pkg/response" "Wavelet/pkg/trace" "Wavelet/pkg/util" + + "github.com/gin-gonic/gin" ) // LoginAdminRequired 返回管理员权限校验中间件 diff --git a/backend/plugins/domain/admin/plugin.go b/backend/plugins/domain/admin/plugin.go index 4dc4cf54..26f5ca4c 100644 --- a/backend/plugins/domain/admin/plugin.go +++ b/backend/plugins/domain/admin/plugin.go @@ -5,16 +5,15 @@ package admin import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/core/extpoints" "context" "embed" "reflect" "github.com/gin-gonic/gin" "github.com/hibiken/asynq" - - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/core/extpoints" ) //go:embed migrations/*/*.sql diff --git a/backend/plugins/domain/admin/plugin_test.go b/backend/plugins/domain/admin/plugin_test.go index ee6e9a98..23ff5a0f 100644 --- a/backend/plugins/domain/admin/plugin_test.go +++ b/backend/plugins/domain/admin/plugin_test.go @@ -4,14 +4,13 @@ package admin_test import ( + "Wavelet/core" + "Wavelet/plugins/domain/admin" "context" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/core" - "Wavelet/plugins/domain/admin" ) func TestAdminPluginUnit(t *testing.T) { diff --git a/backend/plugins/domain/admin/repository.go b/backend/plugins/domain/admin/repository.go index 5c766edd..7e630448 100644 --- a/backend/plugins/domain/admin/repository.go +++ b/backend/plugins/domain/admin/repository.go @@ -4,6 +4,9 @@ package admin import ( + "Wavelet/pkg/cache/ram" + "Wavelet/pkg/idgen" + "Wavelet/pkg/util" "context" "encoding/json" "errors" @@ -14,10 +17,6 @@ import ( "github.com/shopspring/decimal" "gorm.io/gorm" - - "Wavelet/pkg/cache/ram" - "Wavelet/pkg/idgen" - "Wavelet/pkg/util" ) const ( @@ -62,7 +61,7 @@ func PreheatSystemConfigByKey(ctx context.Context, key string) (SystemConfig, er } // GetSystemConfigByGroup queries a configuration by Type and Key. -func GetSystemConfigByGroup(ctx context.Context, configType string, key string) (SystemConfig, error) { +func GetSystemConfigByGroup(ctx context.Context, configType, key string) (SystemConfig, error) { ensureSystemConfigCacheListener() if item, ok := ram.Get(configType, key); ok { @@ -479,7 +478,7 @@ func GetLatestTaskExecutionByTaskType(ctx context.Context, taskType string) (*Ta } // AppendTaskExecutionLog 将日志追加到缓冲,任务完成后再持久化到数据库。 -func AppendTaskExecutionLog(ctx context.Context, taskID string, logLine string) error { +func AppendTaskExecutionLog(ctx context.Context, taskID, logLine string) error { cacheSvc := GetCache(ctx) if cacheSvc == nil { return errors.New("cache service is not initialized") diff --git a/backend/plugins/domain/admin/restart_unix.go b/backend/plugins/domain/admin/restart_unix.go index ae06081f..ca36eec2 100644 --- a/backend/plugins/domain/admin/restart_unix.go +++ b/backend/plugins/domain/admin/restart_unix.go @@ -6,13 +6,12 @@ package admin import ( + "Wavelet/pkg/logger" "context" "fmt" "os" "path/filepath" "syscall" - - "Wavelet/pkg/logger" ) const installedBinaryMode = 0o755 diff --git a/backend/plugins/domain/admin/system_config_cache.go b/backend/plugins/domain/admin/system_config_cache.go index bf5f91ee..069c76e0 100644 --- a/backend/plugins/domain/admin/system_config_cache.go +++ b/backend/plugins/domain/admin/system_config_cache.go @@ -4,14 +4,13 @@ package admin import ( + "Wavelet/pkg/cache/ram" "context" "encoding/json" "errors" "time" "gorm.io/gorm" - - "Wavelet/pkg/cache/ram" ) const ( @@ -57,7 +56,7 @@ func (ConfigLoader) LoadAll(ctx context.Context, configType string) ([]ram.Cache } // LoadOne loads a single system config from database as CacheItem. -func (ConfigLoader) LoadOne(ctx context.Context, configType string, key string) (ram.CacheItem, error) { +func (ConfigLoader) LoadOne(ctx context.Context, configType, key string) (ram.CacheItem, error) { cfg, err := GetSystemConfigByKey(ctx, key) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { diff --git a/backend/plugins/domain/auth/audit.go b/backend/plugins/domain/auth/audit.go index 2189025b..f5755340 100644 --- a/backend/plugins/domain/auth/audit.go +++ b/backend/plugins/domain/auth/audit.go @@ -4,13 +4,12 @@ package auth import ( + "Wavelet/core/contracts" + "Wavelet/pkg/logger" "context" "encoding/json" "github.com/gin-gonic/gin" - - "Wavelet/core/contracts" - "Wavelet/pkg/logger" ) // LogForAudit 将登录鉴权审计日志写入 Logger diff --git a/backend/plugins/domain/auth/auth_source_resolver.go b/backend/plugins/domain/auth/auth_source_resolver.go index e8ddba04..3d56c378 100644 --- a/backend/plugins/domain/auth/auth_source_resolver.go +++ b/backend/plugins/domain/auth/auth_source_resolver.go @@ -4,14 +4,13 @@ package auth import ( + "Wavelet/core/contracts" "context" "errors" "fmt" "strconv" "strings" - "Wavelet/core/contracts" - "github.com/coreos/go-oidc/v3/oidc" "golang.org/x/oauth2" ) @@ -128,7 +127,7 @@ func containsScope(scopes []string, scope string) bool { return false } -func buildOAuthUserInfo(ctx context.Context, source *AuthSource, code string, nonce string, redirectURL string) (*contracts.OAuthUserInfoDTO, error) { +func buildOAuthUserInfo(ctx context.Context, source *AuthSource, code, nonce, redirectURL string) (*contracts.OAuthUserInfoDTO, error) { authConfig, verifier, err := buildOAuthConfig(ctx, source, redirectURL) if err != nil { return nil, err diff --git a/backend/plugins/domain/auth/cache.go b/backend/plugins/domain/auth/cache.go index af418a8c..0beda8ec 100644 --- a/backend/plugins/domain/auth/cache.go +++ b/backend/plugins/domain/auth/cache.go @@ -4,12 +4,11 @@ package auth import ( + "Wavelet/core/contracts" + "Wavelet/pkg/cache/ram" "context" "fmt" "time" - - "Wavelet/core/contracts" - "Wavelet/pkg/cache/ram" ) const ( diff --git a/backend/plugins/domain/auth/cache_test.go b/backend/plugins/domain/auth/cache_test.go index cf58e34a..80e95b6f 100644 --- a/backend/plugins/domain/auth/cache_test.go +++ b/backend/plugins/domain/auth/cache_test.go @@ -4,14 +4,13 @@ package auth_test import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/plugins/domain/auth" "context" "encoding/json" "testing" "time" - - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/plugins/domain/auth" ) type mockCacheService struct { diff --git a/backend/plugins/domain/auth/handlers.go b/backend/plugins/domain/auth/handlers.go index 63e254e4..3fe020d1 100644 --- a/backend/plugins/domain/auth/handlers.go +++ b/backend/plugins/domain/auth/handlers.go @@ -4,6 +4,11 @@ package auth import ( + "Wavelet/core/contracts" + "Wavelet/pkg/idgen" + "Wavelet/pkg/logger" + "Wavelet/pkg/response" + "Wavelet/pkg/util" "context" "errors" "fmt" @@ -12,18 +17,11 @@ import ( "strings" "time" - "Wavelet/core/contracts" - "github.com/coreos/go-oidc/v3/oidc" "github.com/gin-contrib/sessions" "github.com/gin-gonic/gin" "github.com/google/uuid" "gorm.io/gorm" - - "Wavelet/pkg/idgen" - "Wavelet/pkg/logger" - "Wavelet/pkg/response" - "Wavelet/pkg/util" ) // GetLoginSources 获取可用登录源列表 diff --git a/backend/plugins/domain/auth/middleware.go b/backend/plugins/domain/auth/middleware.go index 27df177a..2ef4c130 100644 --- a/backend/plugins/domain/auth/middleware.go +++ b/backend/plugins/domain/auth/middleware.go @@ -4,17 +4,16 @@ package auth import ( + "Wavelet/core/contracts" + "Wavelet/pkg/response" + "Wavelet/pkg/trace" + "Wavelet/pkg/util" "context" "crypto/sha256" "encoding/hex" "errors" "github.com/gin-gonic/gin" - - "Wavelet/core/contracts" - "Wavelet/pkg/response" - "Wavelet/pkg/trace" - "Wavelet/pkg/util" ) func hashToken(token string) string { diff --git a/backend/plugins/domain/auth/models.go b/backend/plugins/domain/auth/models.go index 30d0b949..87e441c1 100644 --- a/backend/plugins/domain/auth/models.go +++ b/backend/plugins/domain/auth/models.go @@ -4,14 +4,13 @@ package auth import ( + "Wavelet/core/contracts" "encoding/json" "errors" "regexp" "strconv" "strings" "time" - - "Wavelet/core/contracts" ) var authSourceNamePattern = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9_-]{0,79}$`) diff --git a/backend/plugins/domain/auth/plugin.go b/backend/plugins/domain/auth/plugin.go index 540af001..639f0ccd 100644 --- a/backend/plugins/domain/auth/plugin.go +++ b/backend/plugins/domain/auth/plugin.go @@ -5,13 +5,12 @@ package auth import ( - "context" - "embed" - "reflect" - "Wavelet/core" "Wavelet/core/contracts" "Wavelet/core/extpoints" + "context" + "embed" + "reflect" ) //go:embed migrations/*/*.sql diff --git a/backend/plugins/domain/auth/plugin_test.go b/backend/plugins/domain/auth/plugin_test.go index 1e7f66c2..2c5b52b8 100644 --- a/backend/plugins/domain/auth/plugin_test.go +++ b/backend/plugins/domain/auth/plugin_test.go @@ -4,6 +4,9 @@ package auth_test import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/plugins/domain/auth" "context" "crypto/sha256" "encoding/hex" @@ -15,10 +18,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gorm.io/gorm" - - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/plugins/domain/auth" ) type mockDBService struct { @@ -84,6 +83,7 @@ func (m *mockProvider) Name() string { return "custom" } func (m *mockProvider) GetAuthURL(state string) string { return "https://custom.com/auth?state=" + state } + func (m *mockProvider) ExchangeCode(ctx context.Context, code string) (*contracts.OAuthUserInfoDTO, error) { return &contracts.OAuthUserInfoDTO{ ID: 555, diff --git a/backend/plugins/domain/auth/repository.go b/backend/plugins/domain/auth/repository.go index c0e3b0c0..2e1e9a78 100644 --- a/backend/plugins/domain/auth/repository.go +++ b/backend/plugins/domain/auth/repository.go @@ -4,13 +4,12 @@ package auth import ( + "Wavelet/core" + "Wavelet/core/contracts" "context" "sync" "gorm.io/gorm" - - "Wavelet/core" - "Wavelet/core/contracts" ) var ( @@ -120,6 +119,6 @@ func ListExternalAccountsByUserID(ctx context.Context, userID uint64) ([]Externa } // UnbindExternalAccount 解绑外部账号 -func UnbindExternalAccount(ctx context.Context, id uint64, userID uint64) error { +func UnbindExternalAccount(ctx context.Context, id, userID uint64) error { return getDB(ctx).Where("id = ? AND user_id = ?", id, userID).Delete(&ExternalAccount{}).Error } diff --git a/backend/plugins/domain/auth/service.go b/backend/plugins/domain/auth/service.go index e8c241d5..dc936f36 100644 --- a/backend/plugins/domain/auth/service.go +++ b/backend/plugins/domain/auth/service.go @@ -4,14 +4,13 @@ package auth import ( + "Wavelet/core/contracts" + "Wavelet/pkg/util" "context" "errors" "sync" "github.com/gin-gonic/gin" - - "Wavelet/core/contracts" - "Wavelet/pkg/util" ) type authServiceImpl struct{} diff --git a/backend/plugins/domain/auth/session.go b/backend/plugins/domain/auth/session.go index d6a8e59b..292cc147 100644 --- a/backend/plugins/domain/auth/session.go +++ b/backend/plugins/domain/auth/session.go @@ -4,6 +4,8 @@ package auth import ( + "Wavelet/core/contracts" + "Wavelet/pkg/config" "context" "crypto/sha256" "encoding/hex" @@ -15,9 +17,6 @@ import ( "github.com/gin-gonic/gin" "github.com/google/uuid" gsessions "github.com/gorilla/sessions" - - "Wavelet/core/contracts" - "Wavelet/pkg/config" ) // GetSessionOptions 根据配置构建 Session 选项 diff --git a/backend/plugins/domain/cap/handlers.go b/backend/plugins/domain/cap/handlers.go index 637009fc..7eb0122c 100644 --- a/backend/plugins/domain/cap/handlers.go +++ b/backend/plugins/domain/cap/handlers.go @@ -4,13 +4,12 @@ package cap import ( - "net/http" - - "github.com/gin-gonic/gin" - "Wavelet/pkg/logger" "Wavelet/pkg/response" "Wavelet/plugins/domain/cap/pow" + "net/http" + + "github.com/gin-gonic/gin" ) // ChallengeResponse is a local type alias for the pow.ChallengeResponse struct diff --git a/backend/plugins/domain/cap/manager.go b/backend/plugins/domain/cap/manager.go index 192a32e0..5fbd04a4 100644 --- a/backend/plugins/domain/cap/manager.go +++ b/backend/plugins/domain/cap/manager.go @@ -5,6 +5,8 @@ package cap import ( + "Wavelet/pkg/config" + "Wavelet/plugins/domain/cap/pow" "context" "crypto/sha256" "encoding/hex" @@ -12,9 +14,6 @@ import ( "strings" "sync" "time" - - "Wavelet/pkg/config" - "Wavelet/plugins/domain/cap/pow" ) const ( @@ -116,7 +115,7 @@ func (m *Manager) Redeem(ctx context.Context, token string, solutions []int, sco } // VerifyToken validates and consumes the redeem token (single-use). -func (m *Manager) VerifyToken(ctx context.Context, token string, expectedScope string) (bool, error) { +func (m *Manager) VerifyToken(ctx context.Context, token, expectedScope string) (bool, error) { if token == "" { return false, nil } diff --git a/backend/plugins/domain/cap/middleware.go b/backend/plugins/domain/cap/middleware.go index a5867e01..643f9e06 100644 --- a/backend/plugins/domain/cap/middleware.go +++ b/backend/plugins/domain/cap/middleware.go @@ -4,9 +4,9 @@ package cap import ( - "github.com/gin-gonic/gin" - "Wavelet/pkg/response" + + "github.com/gin-gonic/gin" ) // VerifyMiddleware returns a Gin middleware that checks and consumes the X-Cap-Token header. diff --git a/backend/plugins/domain/cap/plugin.go b/backend/plugins/domain/cap/plugin.go index ca7c6bdb..20e21b4f 100644 --- a/backend/plugins/domain/cap/plugin.go +++ b/backend/plugins/domain/cap/plugin.go @@ -5,11 +5,10 @@ package cap import ( - "reflect" - "Wavelet/core" "Wavelet/core/contracts" "Wavelet/core/extpoints" + "reflect" ) // Plugin implements core.Plugin to provide CAPTCHA generation, validation, and route protection. diff --git a/backend/plugins/domain/cap/pow/cap.go b/backend/plugins/domain/cap/pow/cap.go index 1d45d066..dc57355c 100644 --- a/backend/plugins/domain/cap/pow/cap.go +++ b/backend/plugins/domain/cap/pow/cap.go @@ -88,7 +88,7 @@ func RandomHex(byteLen int) string { return hex.EncodeToString(bytes) } -func jwtSign(payload []byte, secret []byte) string { +func jwtSign(payload, secret []byte) string { body := b64urlEncode(payload) sigInput := jwtHeaderB64 + "." + body diff --git a/backend/plugins/domain/cap/pow/store.go b/backend/plugins/domain/cap/pow/store.go index 4a4de699..f9f05667 100644 --- a/backend/plugins/domain/cap/pow/store.go +++ b/backend/plugins/domain/cap/pow/store.go @@ -14,12 +14,12 @@ import ( // Store defines the storage interface for challenge nonces and verification tokens type Store interface { Get(ctx context.Context, key string) (string, bool, error) - Set(ctx context.Context, key string, val string, ttl time.Duration) error + Set(ctx context.Context, key, val string, ttl time.Duration) error Delete(ctx context.Context, key string) error // SetNX atomically sets key=val with the given TTL only when the key does not // exist yet. It returns true when the key was actually written (i.e. this // caller "won" the race), and false when the key already existed. - SetNX(ctx context.Context, key string, val string, ttl time.Duration) (bool, error) + SetNX(ctx context.Context, key, val string, ttl time.Duration) (bool, error) // GetAndDelete atomically retrieves the value of key and removes it in a // single operation. Returns ("", false, nil) when the key does not exist. GetAndDelete(ctx context.Context, key string) (string, bool, error) @@ -68,7 +68,7 @@ func (s *MemoryStore) getLocked(key string) (string, bool, error) { } // Set 向 MemoryStore 写入指定 key 的值 -func (s *MemoryStore) Set(_ context.Context, key string, val string, ttl time.Duration) error { +func (s *MemoryStore) Set(_ context.Context, key, val string, ttl time.Duration) error { s.mu.Lock() defer s.mu.Unlock() s.items[key] = memoryItem{ @@ -88,7 +88,7 @@ func (s *MemoryStore) Delete(_ context.Context, key string) error { // SetNX atomically sets key only when it is absent (or expired). // Returns true if the key was written by this call. -func (s *MemoryStore) SetNX(_ context.Context, key string, val string, ttl time.Duration) (bool, error) { +func (s *MemoryStore) SetNX(_ context.Context, key, val string, ttl time.Duration) (bool, error) { s.mu.Lock() defer s.mu.Unlock() @@ -159,7 +159,7 @@ func (s *RedisStore) Get(ctx context.Context, key string) (string, bool, error) } // Set 向 RedisStore 写入指定 key 的值 -func (s *RedisStore) Set(ctx context.Context, key string, val string, ttl time.Duration) error { +func (s *RedisStore) Set(ctx context.Context, key, val string, ttl time.Duration) error { return s.client.Set(ctx, key, val, ttl).Err() } @@ -169,7 +169,7 @@ func (s *RedisStore) Delete(ctx context.Context, key string) error { } // SetNX wraps Redis SET NX – returns true only when the key was newly created. -func (s *RedisStore) SetNX(ctx context.Context, key string, val string, ttl time.Duration) (bool, error) { +func (s *RedisStore) SetNX(ctx context.Context, key, val string, ttl time.Duration) (bool, error) { return s.client.SetNX(ctx, key, val, ttl).Result() } diff --git a/backend/plugins/domain/cap/runtime_settings.go b/backend/plugins/domain/cap/runtime_settings.go index 2ece09e1..73a58bb4 100644 --- a/backend/plugins/domain/cap/runtime_settings.go +++ b/backend/plugins/domain/cap/runtime_settings.go @@ -4,6 +4,8 @@ package cap import ( + "Wavelet/core" + "Wavelet/core/contracts" "context" "errors" "strconv" @@ -13,9 +15,6 @@ import ( "golang.org/x/sync/singleflight" "gorm.io/gorm" - - "Wavelet/core" - "Wavelet/core/contracts" ) var ( diff --git a/backend/plugins/domain/domain_test.go b/backend/plugins/domain/domain_test.go index accd7045..2a7837ee 100644 --- a/backend/plugins/domain/domain_test.go +++ b/backend/plugins/domain/domain_test.go @@ -4,6 +4,16 @@ package domain_test import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/plugins/domain/admin" + "Wavelet/plugins/domain/auth" + "Wavelet/plugins/domain/message_gateway" + "Wavelet/plugins/domain/risk_control" + "Wavelet/plugins/domain/user" + "Wavelet/plugins/infra/cache" + "Wavelet/plugins/infra/logger" + "Wavelet/plugins/infra/storage" "context" "io/fs" "path/filepath" @@ -16,17 +26,7 @@ import ( "github.com/stretchr/testify/require" "gorm.io/gorm" - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/plugins/domain/admin" - "Wavelet/plugins/domain/auth" - "Wavelet/plugins/domain/message_gateway" - "Wavelet/plugins/domain/risk_control" - "Wavelet/plugins/domain/user" - "Wavelet/plugins/infra/cache" db "Wavelet/plugins/infra/database" - "Wavelet/plugins/infra/logger" - "Wavelet/plugins/infra/storage" ) func setupTestDB(t *testing.T) *gorm.DB { diff --git a/backend/plugins/domain/message_gateway/admin_handlers.go b/backend/plugins/domain/message_gateway/admin_handlers.go index b9cf386f..885cd10d 100644 --- a/backend/plugins/domain/message_gateway/admin_handlers.go +++ b/backend/plugins/domain/message_gateway/admin_handlers.go @@ -4,12 +4,11 @@ package message_gateway import ( + "Wavelet/pkg/response" "net/http" "strconv" "github.com/gin-gonic/gin" - - "Wavelet/pkg/response" ) // ListAdminChannelDefinitions returns form schemas for supported channel types. diff --git a/backend/plugins/domain/message_gateway/channels/qq/adapter.go b/backend/plugins/domain/message_gateway/channels/qq/adapter.go index 035b4ecd..97d03a52 100644 --- a/backend/plugins/domain/message_gateway/channels/qq/adapter.go +++ b/backend/plugins/domain/message_gateway/channels/qq/adapter.go @@ -5,17 +5,15 @@ package qq import ( + "Wavelet/pkg/logger" + "Wavelet/pkg/util" + "Wavelet/plugins/domain/message_gateway" "context" "fmt" "strings" "sync" "time" - "Wavelet/pkg/util" - - "Wavelet/pkg/logger" - "Wavelet/plugins/domain/message_gateway" - "github.com/tencent-connect/botgo" "github.com/tencent-connect/botgo/dto" "github.com/tencent-connect/botgo/event" diff --git a/backend/plugins/domain/message_gateway/channels/qq/adapter_test.go b/backend/plugins/domain/message_gateway/channels/qq/adapter_test.go index 793ec6b0..ab1fcd7f 100644 --- a/backend/plugins/domain/message_gateway/channels/qq/adapter_test.go +++ b/backend/plugins/domain/message_gateway/channels/qq/adapter_test.go @@ -4,10 +4,9 @@ package qq import ( + "Wavelet/plugins/domain/message_gateway" "context" "testing" - - "Wavelet/plugins/domain/message_gateway" ) func TestHandleEvent_DropsNonC2C(t *testing.T) { diff --git a/backend/plugins/domain/message_gateway/channels/telegram/adapter.go b/backend/plugins/domain/message_gateway/channels/telegram/adapter.go index d11d14e2..4e5b1ba5 100644 --- a/backend/plugins/domain/message_gateway/channels/telegram/adapter.go +++ b/backend/plugins/domain/message_gateway/channels/telegram/adapter.go @@ -5,6 +5,8 @@ package telegram import ( + "Wavelet/pkg/util" + "Wavelet/plugins/domain/message_gateway" "context" "fmt" "os" @@ -13,9 +15,6 @@ import ( "strings" tele "gopkg.in/telebot.v4" - - "Wavelet/pkg/util" - "Wavelet/plugins/domain/message_gateway" ) // Adapter is a Telegram private-chat channel. diff --git a/backend/plugins/domain/message_gateway/channels/telegram/adapter_test.go b/backend/plugins/domain/message_gateway/channels/telegram/adapter_test.go index b95c7675..17106f31 100644 --- a/backend/plugins/domain/message_gateway/channels/telegram/adapter_test.go +++ b/backend/plugins/domain/message_gateway/channels/telegram/adapter_test.go @@ -4,12 +4,11 @@ package telegram import ( + "Wavelet/plugins/domain/message_gateway" "context" "testing" tele "gopkg.in/telebot.v4" - - "Wavelet/plugins/domain/message_gateway" ) func TestHandleUpdate_DropsGroups(t *testing.T) { diff --git a/backend/plugins/domain/message_gateway/custom_events_admin_login.go b/backend/plugins/domain/message_gateway/custom_events_admin_login.go index dddcd04a..8f70bb8b 100644 --- a/backend/plugins/domain/message_gateway/custom_events_admin_login.go +++ b/backend/plugins/domain/message_gateway/custom_events_admin_login.go @@ -4,10 +4,9 @@ package message_gateway import ( + "Wavelet/core/contracts" "context" "time" - - "Wavelet/core/contracts" ) // AdminLogin is the metadata definition for the admin login event. diff --git a/backend/plugins/domain/message_gateway/db_helper.go b/backend/plugins/domain/message_gateway/db_helper.go index 4b2ce2ae..9d1b5a83 100644 --- a/backend/plugins/domain/message_gateway/db_helper.go +++ b/backend/plugins/domain/message_gateway/db_helper.go @@ -4,13 +4,12 @@ package message_gateway import ( + "Wavelet/core" + "Wavelet/core/contracts" "context" "sync" "gorm.io/gorm" - - "Wavelet/core" - "Wavelet/core/contracts" ) var ( diff --git a/backend/plugins/domain/message_gateway/handlers.go b/backend/plugins/domain/message_gateway/handlers.go index 9adc4603..e01a5bb7 100644 --- a/backend/plugins/domain/message_gateway/handlers.go +++ b/backend/plugins/domain/message_gateway/handlers.go @@ -4,15 +4,14 @@ package message_gateway import ( + "Wavelet/core/contracts" + "Wavelet/pkg/response" + "Wavelet/pkg/util" "errors" "net/http" "strconv" "github.com/gin-gonic/gin" - - "Wavelet/core/contracts" - "Wavelet/pkg/response" - "Wavelet/pkg/util" ) func currentUser(c *gin.Context) (*contracts.UserDTO, bool) { diff --git a/backend/plugins/domain/message_gateway/message_gateway_test.go b/backend/plugins/domain/message_gateway/message_gateway_test.go index 6db02f9e..cec83794 100644 --- a/backend/plugins/domain/message_gateway/message_gateway_test.go +++ b/backend/plugins/domain/message_gateway/message_gateway_test.go @@ -4,14 +4,13 @@ package message_gateway_test import ( + "Wavelet/pkg/testhelper" + "Wavelet/plugins/domain/message_gateway" "context" "testing" "time" "gorm.io/gorm" - - "Wavelet/pkg/testhelper" - "Wavelet/plugins/domain/message_gateway" ) type mockDBService struct { diff --git a/backend/plugins/domain/message_gateway/plugin.go b/backend/plugins/domain/message_gateway/plugin.go index 9ff18809..2da67574 100644 --- a/backend/plugins/domain/message_gateway/plugin.go +++ b/backend/plugins/domain/message_gateway/plugin.go @@ -5,16 +5,15 @@ package message_gateway import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/core/extpoints" + "Wavelet/pkg/util" "context" "embed" "reflect" "github.com/gin-gonic/gin" - - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/core/extpoints" - "Wavelet/pkg/util" ) //go:embed migrations/*/*.sql diff --git a/backend/plugins/domain/message_gateway/plugin_test.go b/backend/plugins/domain/message_gateway/plugin_test.go index 439d7055..f6aca038 100644 --- a/backend/plugins/domain/message_gateway/plugin_test.go +++ b/backend/plugins/domain/message_gateway/plugin_test.go @@ -4,15 +4,14 @@ package message_gateway_test import ( + "Wavelet/core" + "Wavelet/plugins/domain/message_gateway" "context" "io/fs" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/core" - "Wavelet/plugins/domain/message_gateway" ) func TestMessageGatewayPluginUnit(t *testing.T) { diff --git a/backend/plugins/domain/message_gateway/push/custom.go b/backend/plugins/domain/message_gateway/push/custom.go index 954362eb..18a47228 100644 --- a/backend/plugins/domain/message_gateway/push/custom.go +++ b/backend/plugins/domain/message_gateway/push/custom.go @@ -4,6 +4,7 @@ package push import ( + "Wavelet/pkg/httppool" "bytes" "context" "encoding/json" @@ -12,8 +13,6 @@ import ( "io" "net/http" "strings" - - "Wavelet/pkg/httppool" ) func init() { diff --git a/backend/plugins/domain/message_gateway/push/email.go b/backend/plugins/domain/message_gateway/push/email.go index 0f439fa9..48e501bc 100644 --- a/backend/plugins/domain/message_gateway/push/email.go +++ b/backend/plugins/domain/message_gateway/push/email.go @@ -4,14 +4,13 @@ package push import ( + "Wavelet/pkg/util" "context" "errors" "fmt" "net" "net/smtp" "strings" - - "Wavelet/pkg/util" ) func init() { diff --git a/backend/plugins/domain/message_gateway/push/lark.go b/backend/plugins/domain/message_gateway/push/lark.go index 24b66237..de15d83b 100644 --- a/backend/plugins/domain/message_gateway/push/lark.go +++ b/backend/plugins/domain/message_gateway/push/lark.go @@ -4,6 +4,7 @@ package push import ( + "Wavelet/pkg/httppool" "bytes" "context" "crypto/hmac" @@ -16,8 +17,6 @@ import ( "strconv" "strings" "time" - - "Wavelet/pkg/httppool" ) func init() { diff --git a/backend/plugins/domain/message_gateway/push/telegram.go b/backend/plugins/domain/message_gateway/push/telegram.go index 426e1bb7..65aeae0f 100644 --- a/backend/plugins/domain/message_gateway/push/telegram.go +++ b/backend/plugins/domain/message_gateway/push/telegram.go @@ -4,6 +4,7 @@ package push import ( + "Wavelet/pkg/httppool" "bytes" "context" "encoding/json" @@ -11,8 +12,6 @@ import ( "fmt" "net/http" "strings" - - "Wavelet/pkg/httppool" ) func init() { diff --git a/backend/plugins/domain/message_gateway/push_channels.go b/backend/plugins/domain/message_gateway/push_channels.go index ee559407..37726b63 100644 --- a/backend/plugins/domain/message_gateway/push_channels.go +++ b/backend/plugins/domain/message_gateway/push_channels.go @@ -4,6 +4,7 @@ package message_gateway import ( + "Wavelet/pkg/response" "encoding/json" "errors" "net/http" @@ -14,7 +15,6 @@ import ( "github.com/gin-gonic/gin" "gorm.io/gorm" - "Wavelet/pkg/response" pkgpush "Wavelet/plugins/domain/message_gateway/push" ) diff --git a/backend/plugins/domain/message_gateway/push_events.go b/backend/plugins/domain/message_gateway/push_events.go index 8c91d0e1..2109c9e2 100644 --- a/backend/plugins/domain/message_gateway/push_events.go +++ b/backend/plugins/domain/message_gateway/push_events.go @@ -4,18 +4,16 @@ package message_gateway import ( + "Wavelet/pkg/logger" + "Wavelet/pkg/util" "context" "encoding/json" "errors" "sync" - "Wavelet/pkg/logger" - pkgpush "Wavelet/plugins/domain/message_gateway/push" "gorm.io/gorm" - - "Wavelet/pkg/util" ) // NotificationMessage represents the structured notification message payload. @@ -122,7 +120,7 @@ func (t *EventTrigger) Trigger(ctx context.Context, meta EventMetadata, body map }) } -func (t *EventTrigger) buildMessage(event *PushEvent, meta EventMetadata, flatBody map[string]any, body map[string]any) (NotificationMessage, string) { +func (t *EventTrigger) buildMessage(event *PushEvent, meta EventMetadata, flatBody, body map[string]any) (NotificationMessage, string) { var msg NotificationMessage renderedTemplate := "" diff --git a/backend/plugins/domain/message_gateway/push_handlers.go b/backend/plugins/domain/message_gateway/push_handlers.go index 0dd5e1c1..41ed9af8 100644 --- a/backend/plugins/domain/message_gateway/push_handlers.go +++ b/backend/plugins/domain/message_gateway/push_handlers.go @@ -4,6 +4,7 @@ package message_gateway import ( + "Wavelet/pkg/response" "errors" "fmt" "net/http" @@ -13,8 +14,6 @@ import ( "github.com/gin-gonic/gin" "gorm.io/gorm" - - "Wavelet/pkg/response" ) // UpdatePushEventRequest is the request body for updating a push event. diff --git a/backend/plugins/domain/message_gateway/push_logics.go b/backend/plugins/domain/message_gateway/push_logics.go index b1777f76..688019f3 100644 --- a/backend/plugins/domain/message_gateway/push_logics.go +++ b/backend/plugins/domain/message_gateway/push_logics.go @@ -4,6 +4,7 @@ package message_gateway import ( + "Wavelet/core/contracts" "context" "encoding/json" "errors" @@ -13,7 +14,6 @@ import ( "gorm.io/gorm" - "Wavelet/core/contracts" pkgpush "Wavelet/plugins/domain/message_gateway/push" ) @@ -368,7 +368,7 @@ func resolveDynamicKeyword(target string, flatBody map[string]any) string { return target } -func resolveTargetUser(ctx context.Context, resolved string, _ string) (contracts.UserDTO, bool) { +func resolveTargetUser(ctx context.Context, resolved, _ string) (contracts.UserDTO, bool) { var user contracts.UserDTO if id, err := strconv.ParseUint(resolved, 10, 64); err == nil { if err := getDB(ctx).Table("w_users").Where("id = ?", id).First(&user).Error; err == nil { @@ -381,7 +381,7 @@ func resolveTargetUser(ctx context.Context, resolved string, _ string) (contract return user, false } -func resolveSystemTarget(ctx context.Context, resolved string, channel string) (string, bool) { +func resolveSystemTarget(ctx context.Context, resolved, channel string) (string, bool) { if resolved != "系统" && resolved != "system" && resolved != "0" { return "", false } @@ -507,7 +507,7 @@ func getFlatBody(body map[string]any) map[string]any { return flatResult } -func flattenMap(prefix string, m map[string]any, result map[string]any) { +func flattenMap(prefix string, m, result map[string]any) { for k, v := range m { key := k if prefix != "" { diff --git a/backend/plugins/domain/message_gateway/push_task_listener.go b/backend/plugins/domain/message_gateway/push_task_listener.go index 4b62f372..7d7b5dac 100644 --- a/backend/plugins/domain/message_gateway/push_task_listener.go +++ b/backend/plugins/domain/message_gateway/push_task_listener.go @@ -4,13 +4,12 @@ package message_gateway import ( + "Wavelet/core/contracts" + "Wavelet/pkg/logger" "context" "encoding/json" "strconv" "time" - - "Wavelet/core/contracts" - "Wavelet/pkg/logger" ) func handleTaskCompleted(ctx context.Context, e contracts.TaskCompletedEvent) { @@ -59,7 +58,7 @@ func handleTaskCompleted(ctx context.Context, e contracts.TaskCompletedEvent) { } } -func extractUserFromMap(ctx context.Context, data map[string]any, body map[string]any) { +func extractUserFromMap(ctx context.Context, data, body map[string]any) { if u, exists := body["user"]; exists && u != nil { return } diff --git a/backend/plugins/domain/message_gateway/push_tasks.go b/backend/plugins/domain/message_gateway/push_tasks.go index 61966935..1e265aaf 100644 --- a/backend/plugins/domain/message_gateway/push_tasks.go +++ b/backend/plugins/domain/message_gateway/push_tasks.go @@ -4,14 +4,13 @@ package message_gateway import ( + "Wavelet/core/contracts" + "Wavelet/pkg/logger" + "Wavelet/plugins/domain/message_gateway/push" "context" "encoding/json" "errors" "fmt" - - "Wavelet/core/contracts" - "Wavelet/pkg/logger" - "Wavelet/plugins/domain/message_gateway/push" ) const ( @@ -101,7 +100,7 @@ func (h *PushHandler) Execute(ctx context.Context, payload []byte) error { return nil } -func (h *PushHandler) recordHistory(ctx context.Context, req SendPayload, status string, errMsg string) { +func (h *PushHandler) recordHistory(ctx context.Context, req SendPayload, status, errMsg string) { if dbErr := recordPushHistory(ctx, req, status, errMsg); dbErr != nil { logger.ErrorF(ctx, "[Push] 写入推送历史审计记录失败: %v", dbErr) } diff --git a/backend/plugins/domain/message_gateway/repository.go b/backend/plugins/domain/message_gateway/repository.go index e47395eb..3221cf7b 100644 --- a/backend/plugins/domain/message_gateway/repository.go +++ b/backend/plugins/domain/message_gateway/repository.go @@ -4,13 +4,12 @@ package message_gateway import ( + "Wavelet/pkg/idgen" "context" "errors" "time" "gorm.io/gorm" - - "Wavelet/pkg/idgen" ) const ( diff --git a/backend/plugins/domain/message_gateway/runner.go b/backend/plugins/domain/message_gateway/runner.go index 78b7b630..e2dd728a 100644 --- a/backend/plugins/domain/message_gateway/runner.go +++ b/backend/plugins/domain/message_gateway/runner.go @@ -4,10 +4,9 @@ package message_gateway import ( + "Wavelet/pkg/logger" "context" "sync" - - "Wavelet/pkg/logger" ) // Runner manages lifecycle for long-lived channel adapters (WebSocket, long-polling, etc.). diff --git a/backend/plugins/domain/message_gateway/secret.go b/backend/plugins/domain/message_gateway/secret.go index 560aa0b6..373e7145 100644 --- a/backend/plugins/domain/message_gateway/secret.go +++ b/backend/plugins/domain/message_gateway/secret.go @@ -4,12 +4,11 @@ package message_gateway import ( + "Wavelet/pkg/config" + "Wavelet/pkg/util" "crypto/sha256" "encoding/hex" "encoding/json" - - "Wavelet/pkg/config" - "Wavelet/pkg/util" ) // CredentialKey is AES-256 hex derived from the session secret. diff --git a/backend/plugins/domain/risk_control/logics.go b/backend/plugins/domain/risk_control/logics.go index 2779e97d..cf0f6695 100644 --- a/backend/plugins/domain/risk_control/logics.go +++ b/backend/plugins/domain/risk_control/logics.go @@ -4,13 +4,12 @@ package risk_control import ( - "context" - "sync" - "time" - "Wavelet/pkg/batchwriter" "Wavelet/pkg/logger" "Wavelet/plugins/domain/risk_control/logstore" + "context" + "sync" + "time" ) var ( diff --git a/backend/plugins/domain/risk_control/logstore/access_log.go b/backend/plugins/domain/risk_control/logstore/access_log.go index ec8788fe..154f71d8 100644 --- a/backend/plugins/domain/risk_control/logstore/access_log.go +++ b/backend/plugins/domain/risk_control/logstore/access_log.go @@ -5,13 +5,12 @@ package logstore import ( + "Wavelet/pkg/util" "context" "fmt" "time" "gorm.io/gorm" - - "Wavelet/pkg/util" ) // CountAccessLogs returns the number of access logs matching filter. diff --git a/backend/plugins/domain/risk_control/logstore/access_log_test.go b/backend/plugins/domain/risk_control/logstore/access_log_test.go index 71040b7e..376c980f 100644 --- a/backend/plugins/domain/risk_control/logstore/access_log_test.go +++ b/backend/plugins/domain/risk_control/logstore/access_log_test.go @@ -169,9 +169,9 @@ func (m *mockConn) Exec(_ context.Context, _ string, _ ...any) error { return ni func (m *mockConn) AsyncInsert(_ context.Context, _ string, _ bool, _ ...any) error { return nil } -func (m *mockConn) InsertFormat(_ context.Context, _ string, _ string, _ io.Reader) error { return nil } +func (m *mockConn) InsertFormat(_ context.Context, _, _ string, _ io.Reader) error { return nil } -func (m *mockConn) QueryFormat(_ context.Context, _ string, _ string, _ ...any) (io.ReadCloser, error) { +func (m *mockConn) QueryFormat(_ context.Context, _, _ string, _ ...any) (io.ReadCloser, error) { return nil, nil } diff --git a/backend/plugins/domain/risk_control/logstore/cleanup.go b/backend/plugins/domain/risk_control/logstore/cleanup.go index 2b4f04be..b1a1c6f4 100644 --- a/backend/plugins/domain/risk_control/logstore/cleanup.go +++ b/backend/plugins/domain/risk_control/logstore/cleanup.go @@ -4,13 +4,12 @@ package logstore import ( + "Wavelet/pkg/logger" "context" "errors" "fmt" "strconv" "time" - - "Wavelet/pkg/logger" ) const ( diff --git a/backend/plugins/domain/risk_control/logstore/db_helper.go b/backend/plugins/domain/risk_control/logstore/db_helper.go index c5f366d7..af540ef9 100644 --- a/backend/plugins/domain/risk_control/logstore/db_helper.go +++ b/backend/plugins/domain/risk_control/logstore/db_helper.go @@ -4,14 +4,13 @@ package logstore import ( + "Wavelet/core" + "Wavelet/core/contracts" "context" "sync" "github.com/ClickHouse/clickhouse-go/v2/lib/driver" "gorm.io/gorm" - - "Wavelet/core" - "Wavelet/core/contracts" ) var ( diff --git a/backend/plugins/domain/risk_control/logstore/gorm.go b/backend/plugins/domain/risk_control/logstore/gorm.go index a2a2568b..cf79ec6c 100644 --- a/backend/plugins/domain/risk_control/logstore/gorm.go +++ b/backend/plugins/domain/risk_control/logstore/gorm.go @@ -4,6 +4,7 @@ package logstore import ( + "Wavelet/pkg/idgen" "context" "errors" "fmt" @@ -12,8 +13,6 @@ import ( "time" "gorm.io/gorm" - - "Wavelet/pkg/idgen" ) const ( diff --git a/backend/plugins/domain/risk_control/logstore/provider.go b/backend/plugins/domain/risk_control/logstore/provider.go index c8833ca5..83b6abd5 100644 --- a/backend/plugins/domain/risk_control/logstore/provider.go +++ b/backend/plugins/domain/risk_control/logstore/provider.go @@ -4,14 +4,13 @@ package logstore import ( + "Wavelet/pkg/config" + "Wavelet/pkg/logger" "context" "errors" "fmt" "sync" "time" - - "Wavelet/pkg/config" - "Wavelet/pkg/logger" ) const ( diff --git a/backend/plugins/domain/risk_control/middleware.go b/backend/plugins/domain/risk_control/middleware.go index 93087f27..44cfd82d 100644 --- a/backend/plugins/domain/risk_control/middleware.go +++ b/backend/plugins/domain/risk_control/middleware.go @@ -5,18 +5,17 @@ package risk_control import ( - "encoding/json" - "net/http" - "time" - - "github.com/gin-gonic/gin" - "Wavelet/core/contracts" "Wavelet/pkg/config" "Wavelet/pkg/idgen" "Wavelet/pkg/response" "Wavelet/pkg/util" "Wavelet/plugins/domain/risk_control/logstore" + "encoding/json" + "net/http" + "time" + + "github.com/gin-gonic/gin" ) // Middleware is an alias for RiskControlMiddleware. diff --git a/backend/plugins/domain/risk_control/middleware_test.go b/backend/plugins/domain/risk_control/middleware_test.go index 22e2a6fc..c8af3113 100644 --- a/backend/plugins/domain/risk_control/middleware_test.go +++ b/backend/plugins/domain/risk_control/middleware_test.go @@ -4,6 +4,13 @@ package risk_control_test import ( + "Wavelet/core/contracts" + "Wavelet/pkg/batchwriter" + "Wavelet/pkg/config" + "Wavelet/pkg/testhelper" + "Wavelet/pkg/util" + "Wavelet/plugins/domain/risk_control" + "Wavelet/plugins/domain/risk_control/logstore" "context" "encoding/json" "net/http" @@ -14,14 +21,6 @@ import ( "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" - - "Wavelet/core/contracts" - "Wavelet/pkg/batchwriter" - "Wavelet/pkg/config" - "Wavelet/pkg/testhelper" - "Wavelet/pkg/util" - "Wavelet/plugins/domain/risk_control" - "Wavelet/plugins/domain/risk_control/logstore" ) func newTestAccessLogWriter(t *testing.T, cfg batchwriter.Config) (*batchwriter.Writer[*logstore.UserAccessLog], func() []*logstore.UserAccessLog) { diff --git a/backend/plugins/domain/risk_control/plugin.go b/backend/plugins/domain/risk_control/plugin.go index 5027e4b8..353ef27e 100644 --- a/backend/plugins/domain/risk_control/plugin.go +++ b/backend/plugins/domain/risk_control/plugin.go @@ -5,16 +5,15 @@ package risk_control import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/core/extpoints" + "Wavelet/plugins/domain/risk_control/logstore" "context" "embed" "reflect" "github.com/gin-gonic/gin" - - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/core/extpoints" - "Wavelet/plugins/domain/risk_control/logstore" ) //go:embed logstore/migrations/*/*.sql diff --git a/backend/plugins/domain/risk_control/plugin_test.go b/backend/plugins/domain/risk_control/plugin_test.go index 36d01c67..fbc37a6d 100644 --- a/backend/plugins/domain/risk_control/plugin_test.go +++ b/backend/plugins/domain/risk_control/plugin_test.go @@ -4,15 +4,14 @@ package risk_control_test import ( + "Wavelet/core" + "Wavelet/plugins/domain/risk_control" "context" "testing" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/core" - "Wavelet/plugins/domain/risk_control" ) func TestRiskControlPluginUnit(t *testing.T) { diff --git a/backend/plugins/domain/system/plugin.go b/backend/plugins/domain/system/plugin.go index 46d3efb5..a0c39d59 100644 --- a/backend/plugins/domain/system/plugin.go +++ b/backend/plugins/domain/system/plugin.go @@ -5,15 +5,14 @@ package system import ( - "net/http" - "reflect" - - "github.com/gin-gonic/gin" - "Wavelet/core" "Wavelet/core/contracts" "Wavelet/pkg/config" "Wavelet/pkg/response" + "net/http" + "reflect" + + "github.com/gin-gonic/gin" ) // Plugin implements core.Plugin to provide system-level basic routes. diff --git a/backend/plugins/domain/upload/cache/access_cache.go b/backend/plugins/domain/upload/cache/access_cache.go index 1cfa6457..e755aa80 100644 --- a/backend/plugins/domain/upload/cache/access_cache.go +++ b/backend/plugins/domain/upload/cache/access_cache.go @@ -5,13 +5,13 @@ package cache import ( + "Wavelet/plugins/domain/upload/shared" "context" "encoding/json" "strings" "sync" "time" - "Wavelet/plugins/domain/upload/shared" uploadstorage "Wavelet/plugins/domain/upload/storage" ) diff --git a/backend/plugins/domain/upload/cache/access_cache_test.go b/backend/plugins/domain/upload/cache/access_cache_test.go index f6e47c50..e4d47833 100644 --- a/backend/plugins/domain/upload/cache/access_cache_test.go +++ b/backend/plugins/domain/upload/cache/access_cache_test.go @@ -4,11 +4,11 @@ package cache import ( + "Wavelet/plugins/domain/upload/shared" "context" "testing" "time" - "Wavelet/plugins/domain/upload/shared" uploadstorage "Wavelet/plugins/domain/upload/storage" ) diff --git a/backend/plugins/domain/upload/cache/meta_cache.go b/backend/plugins/domain/upload/cache/meta_cache.go index df43987e..c9fe703b 100644 --- a/backend/plugins/domain/upload/cache/meta_cache.go +++ b/backend/plugins/domain/upload/cache/meta_cache.go @@ -4,15 +4,14 @@ package cache import ( + "Wavelet/pkg/cache/ram" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/shared" "context" "fmt" "time" "gorm.io/gorm" - - "Wavelet/pkg/cache/ram" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/shared" ) const ( @@ -21,9 +20,7 @@ const ( uploadMetaInvalidationChan = "upload:meta_invalidation" ) -var ( - uploadMetaRAM = ram.MustNew[uint64, models.Upload](ram.Options{MaximumSize: uploadMetaRAMMaximumSize}) -) +var uploadMetaRAM = ram.MustNew[uint64, models.Upload](ram.Options{MaximumSize: uploadMetaRAMMaximumSize}) func uploadMetaRedisKey(id uint64) string { return fmt.Sprintf("upload:meta:%d", id) diff --git a/backend/plugins/domain/upload/cache/meta_cache_test.go b/backend/plugins/domain/upload/cache/meta_cache_test.go index ca5ef1be..1fc3e719 100644 --- a/backend/plugins/domain/upload/cache/meta_cache_test.go +++ b/backend/plugins/domain/upload/cache/meta_cache_test.go @@ -4,14 +4,13 @@ package cache import ( + "Wavelet/pkg/testhelper" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/shared" "context" "testing" "gorm.io/gorm" - - "Wavelet/pkg/testhelper" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/shared" ) func init() { diff --git a/backend/plugins/domain/upload/filesrv/file_server.go b/backend/plugins/domain/upload/filesrv/file_server.go index 2b922cdb..276d8d30 100644 --- a/backend/plugins/domain/upload/filesrv/file_server.go +++ b/backend/plugins/domain/upload/filesrv/file_server.go @@ -5,6 +5,13 @@ package filesrv import ( + "Wavelet/core/contracts" + "Wavelet/pkg/logger" + "Wavelet/pkg/response" + "Wavelet/plugins/domain/upload/cache" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/shared" + "Wavelet/plugins/domain/upload/util" "bytes" "context" "errors" @@ -15,16 +22,11 @@ import ( "strings" "sync" - "Wavelet/core/contracts" pkgcache "Wavelet/pkg/cache/disk" - "Wavelet/pkg/logger" - "Wavelet/pkg/response" + pkgutil "Wavelet/pkg/util" - "Wavelet/plugins/domain/upload/cache" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/shared" + uploadstorage "Wavelet/plugins/domain/upload/storage" - "Wavelet/plugins/domain/upload/util" "github.com/gin-gonic/gin" "golang.org/x/sync/singleflight" diff --git a/backend/plugins/domain/upload/filesrv/file_server_test.go b/backend/plugins/domain/upload/filesrv/file_server_test.go index d03a0614..a9f617c1 100644 --- a/backend/plugins/domain/upload/filesrv/file_server_test.go +++ b/backend/plugins/domain/upload/filesrv/file_server_test.go @@ -4,6 +4,12 @@ package filesrv import ( + "Wavelet/core/contracts" + "Wavelet/pkg/response" + "Wavelet/pkg/testhelper" + "Wavelet/plugins/domain/upload/cache" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/shared" "bytes" "context" "crypto/sha256" @@ -23,12 +29,6 @@ import ( "github.com/gin-contrib/sessions/cookie" "github.com/gin-gonic/gin" - "Wavelet/core/contracts" - "Wavelet/pkg/response" - "Wavelet/pkg/testhelper" - "Wavelet/plugins/domain/upload/cache" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/shared" uploadutil "Wavelet/plugins/domain/upload/util" ) @@ -45,7 +45,7 @@ func (s *localTestStorageService) Put(_ context.Context, key string, body io.Rea s.mu.Lock() defer s.mu.Unlock() path := filepath.Join(s.root, key) - _ = os.MkdirAll(filepath.Dir(path), 0755) + _ = os.MkdirAll(filepath.Dir(path), 0o755) f, err := os.Create(path) if err != nil { return contracts.StoragePutResult{}, err @@ -140,10 +140,10 @@ func TestServeFileByIDAccessControl(t *testing.T) { AccessMode: 1, } - if err := os.WriteFile(filepath.Join(tempDir, "avatar.png"), []byte("image"), 0644); err != nil { + if err := os.WriteFile(filepath.Join(tempDir, "avatar.png"), []byte("image"), 0o644); err != nil { t.Fatalf("failed to write avatar file: %v", err) } - if err := os.WriteFile(filepath.Join(tempDir, "doc.pdf"), []byte("bytes"), 0644); err != nil { + if err := os.WriteFile(filepath.Join(tempDir, "doc.pdf"), []byte("bytes"), 0o644); err != nil { t.Fatalf("failed to write attachment file: %v", err) } @@ -235,7 +235,7 @@ func TestServeFileByIDImageCompression(t *testing.T) { } filePath := filepath.Join(tempDir, "test_image.png") - if err := os.WriteFile(filePath, pngBuf.Bytes(), 0644); err != nil { + if err := os.WriteFile(filePath, pngBuf.Bytes(), 0o644); err != nil { t.Fatalf("failed to write test png: %v", err) } diff --git a/backend/plugins/domain/upload/handler/file_management.go b/backend/plugins/domain/upload/handler/file_management.go index c0fcf336..1e25371e 100644 --- a/backend/plugins/domain/upload/handler/file_management.go +++ b/backend/plugins/domain/upload/handler/file_management.go @@ -4,11 +4,6 @@ package handler import ( - "net/http" - "strconv" - - "github.com/gin-gonic/gin" - "Wavelet/core/contracts" "Wavelet/pkg/response" "Wavelet/pkg/util" @@ -16,6 +11,11 @@ import ( "Wavelet/plugins/domain/upload/models" "Wavelet/plugins/domain/upload/repository" "Wavelet/plugins/domain/upload/shared" + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + uploadstorage "Wavelet/plugins/domain/upload/storage" ) diff --git a/backend/plugins/domain/upload/handler/file_management_test.go b/backend/plugins/domain/upload/handler/file_management_test.go index 3d432145..1cf77e2b 100644 --- a/backend/plugins/domain/upload/handler/file_management_test.go +++ b/backend/plugins/domain/upload/handler/file_management_test.go @@ -4,16 +4,15 @@ package handler import ( + "Wavelet/core/contracts" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/shared" "encoding/json" "net/http" "net/http/httptest" "testing" "github.com/gin-gonic/gin" - - "Wavelet/core/contracts" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/shared" ) func TestGetDistinctUploadTypes(t *testing.T) { diff --git a/backend/plugins/domain/upload/handler/logics.go b/backend/plugins/domain/upload/handler/logics.go index d05f7c0d..161baf6f 100644 --- a/backend/plugins/domain/upload/handler/logics.go +++ b/backend/plugins/domain/upload/handler/logics.go @@ -4,15 +4,14 @@ package handler import ( + "Wavelet/plugins/domain/upload/ingest" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/repository" "context" "errors" "sort" "gorm.io/gorm" - - "Wavelet/plugins/domain/upload/ingest" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/repository" ) func listUploadFiles(ctx context.Context, filter repository.UploadListFilter) (int64, []models.Upload, error) { diff --git a/backend/plugins/domain/upload/handler/routers.go b/backend/plugins/domain/upload/handler/routers.go index 641cdd0c..6f0b44dc 100644 --- a/backend/plugins/domain/upload/handler/routers.go +++ b/backend/plugins/domain/upload/handler/routers.go @@ -5,6 +5,14 @@ package handler import ( + "Wavelet/core/contracts" + "Wavelet/pkg/logger" + "Wavelet/pkg/response" + "Wavelet/plugins/domain/upload/filesrv" + "Wavelet/plugins/domain/upload/ingest" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/shared" + "Wavelet/plugins/domain/upload/util" "archive/zip" "bufio" "bytes" @@ -24,16 +32,9 @@ import ( "github.com/gin-gonic/gin" "gorm.io/gorm" - "Wavelet/core/contracts" - "Wavelet/pkg/logger" - "Wavelet/pkg/response" pkgutil "Wavelet/pkg/util" - "Wavelet/plugins/domain/upload/filesrv" - "Wavelet/plugins/domain/upload/ingest" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/shared" + uploadstorage "Wavelet/plugins/domain/upload/storage" - "Wavelet/plugins/domain/upload/util" ) type batchDownloadRequest struct { diff --git a/backend/plugins/domain/upload/handler/routers_test.go b/backend/plugins/domain/upload/handler/routers_test.go index 1031ee31..dfaaa434 100644 --- a/backend/plugins/domain/upload/handler/routers_test.go +++ b/backend/plugins/domain/upload/handler/routers_test.go @@ -4,6 +4,11 @@ package handler import ( + "Wavelet/core/contracts" + "Wavelet/pkg/response" + "Wavelet/pkg/util" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/shared" "archive/zip" "bytes" "context" @@ -22,11 +27,6 @@ import ( "github.com/gin-gonic/gin" - "Wavelet/core/contracts" - "Wavelet/pkg/response" - "Wavelet/pkg/util" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/shared" uploadstats "Wavelet/plugins/domain/upload/stats" ) @@ -112,8 +112,8 @@ func (s *handlerTestStorage) Put(_ context.Context, key string, body io.Reader, *s.putCount++ } if strings.HasPrefix(key, "uploads/") { - _ = os.MkdirAll(filepath.Dir(key), 0755) - _ = os.WriteFile(key, data, 0644) + _ = os.MkdirAll(filepath.Dir(key), 0o755) + _ = os.WriteFile(key, data, 0o644) } return contracts.StoragePutResult{Key: key, Bucket: "test-bucket"}, nil } @@ -367,11 +367,11 @@ func TestDownloadFile(t *testing.T) { } // Create local file - err := os.MkdirAll("uploads", 0755) + err := os.MkdirAll("uploads", 0o755) if err != nil { t.Fatalf("failed to create directory: %v", err) } - err = os.WriteFile(localUpload.FilePath, []byte("hello download"), 0644) + err = os.WriteFile(localUpload.FilePath, []byte("hello download"), 0o644) if err != nil { t.Fatalf("failed to write file: %v", err) } @@ -563,14 +563,14 @@ func TestBatchDownloadFiles(t *testing.T) { router := setupTestRouter(authUser) // Create and write files locally - err := os.MkdirAll("uploads", 0755) + err := os.MkdirAll("uploads", 0o755) if err != nil { t.Fatalf("failed to create local dir: %v", err) } - _ = os.WriteFile("uploads/f1.txt", []byte("file1 content"), 0644) - _ = os.WriteFile("uploads/f2.txt", []byte("file2 content"), 0644) - _ = os.WriteFile("uploads/f3.txt", []byte("duplicate name file content"), 0644) + _ = os.WriteFile("uploads/f1.txt", []byte("file1 content"), 0o644) + _ = os.WriteFile("uploads/f2.txt", []byte("file2 content"), 0o644) + _ = os.WriteFile("uploads/f3.txt", []byte("duplicate name file content"), 0o644) // Seed upload records. Note f2 and f3 have the same FileName "file_a.txt" to trigger name collision resolution. uploads := []models.Upload{ diff --git a/backend/plugins/domain/upload/handler/stats.go b/backend/plugins/domain/upload/handler/stats.go index f30eca5b..e1a9a472 100644 --- a/backend/plugins/domain/upload/handler/stats.go +++ b/backend/plugins/domain/upload/handler/stats.go @@ -4,13 +4,12 @@ package handler import ( + "Wavelet/pkg/response" + "Wavelet/plugins/domain/upload/shared" "net/http" "time" "github.com/gin-gonic/gin" - - "Wavelet/pkg/response" - "Wavelet/plugins/domain/upload/shared" ) type trendItem struct { diff --git a/backend/plugins/domain/upload/ingest/errors.go b/backend/plugins/domain/upload/ingest/errors.go index 31eb7525..20bf747f 100644 --- a/backend/plugins/domain/upload/ingest/errors.go +++ b/backend/plugins/domain/upload/ingest/errors.go @@ -4,9 +4,8 @@ package ingest import ( - "errors" - "Wavelet/plugins/domain/upload/shared" + "errors" ) // ErrForbidden indicates the caller is not allowed to mutate the upload record. diff --git a/backend/plugins/domain/upload/ingest/helpers.go b/backend/plugins/domain/upload/ingest/helpers.go index fba961cf..660f9e20 100644 --- a/backend/plugins/domain/upload/ingest/helpers.go +++ b/backend/plugins/domain/upload/ingest/helpers.go @@ -4,6 +4,11 @@ package ingest import ( + "Wavelet/pkg/idgen" + "Wavelet/pkg/logger" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/repository" + "Wavelet/plugins/domain/upload/shared" "context" "encoding/json" "errors" @@ -14,12 +19,8 @@ import ( "gorm.io/gorm" - "Wavelet/pkg/idgen" - "Wavelet/pkg/logger" uploadcache "Wavelet/plugins/domain/upload/cache" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/repository" - "Wavelet/plugins/domain/upload/shared" + uploadstats "Wavelet/plugins/domain/upload/stats" uploadstorage "Wavelet/plugins/domain/upload/storage" ) diff --git a/backend/plugins/domain/upload/ingest/ingest.go b/backend/plugins/domain/upload/ingest/ingest.go index dcc2633f..db5ca4a5 100644 --- a/backend/plugins/domain/upload/ingest/ingest.go +++ b/backend/plugins/domain/upload/ingest/ingest.go @@ -4,13 +4,12 @@ package ingest import ( + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/repository" "context" "errors" "gorm.io/gorm" - - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/repository" ) // Ingest stores or resolves an upload using the configured policy and side effects. diff --git a/backend/plugins/domain/upload/ingest/ingest_test.go b/backend/plugins/domain/upload/ingest/ingest_test.go index 276b7d07..7dbf92a2 100644 --- a/backend/plugins/domain/upload/ingest/ingest_test.go +++ b/backend/plugins/domain/upload/ingest/ingest_test.go @@ -4,6 +4,9 @@ package ingest import ( + "Wavelet/core/contracts" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/shared" "bytes" "context" "crypto/sha256" @@ -12,10 +15,6 @@ import ( "os" "sync" "testing" - - "Wavelet/core/contracts" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/shared" ) type testStorageService struct { @@ -64,7 +63,7 @@ func (s *testStorageService) Ingest(_ context.Context, _ io.Reader, _ contracts. return nil, nil } -func setupMockStorage(t *testing.T, putCount *int) (restore func(), disable func()) { +func setupMockStorage(t *testing.T, putCount *int) (restore, disable func()) { t.Helper() mockSvc := &testStorageService{ mockFiles: make(map[string][]byte), diff --git a/backend/plugins/domain/upload/ingest/remove.go b/backend/plugins/domain/upload/ingest/remove.go index 9d17c7f2..27eea984 100644 --- a/backend/plugins/domain/upload/ingest/remove.go +++ b/backend/plugins/domain/upload/ingest/remove.go @@ -4,14 +4,15 @@ package ingest import ( + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/repository" + "Wavelet/plugins/domain/upload/shared" "context" "gorm.io/gorm" uploadcache "Wavelet/plugins/domain/upload/cache" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/repository" - "Wavelet/plugins/domain/upload/shared" + uploadstats "Wavelet/plugins/domain/upload/stats" ) diff --git a/backend/plugins/domain/upload/ingest/types.go b/backend/plugins/domain/upload/ingest/types.go index a62424bf..b4cbaebf 100644 --- a/backend/plugins/domain/upload/ingest/types.go +++ b/backend/plugins/domain/upload/ingest/types.go @@ -5,9 +5,8 @@ package ingest import ( - "io" - "Wavelet/plugins/domain/upload/models" + "io" ) // Policy controls how ingest handles hash collisions and record creation. diff --git a/backend/plugins/domain/upload/plugin.go b/backend/plugins/domain/upload/plugin.go index af076ac1..bc0c224b 100644 --- a/backend/plugins/domain/upload/plugin.go +++ b/backend/plugins/domain/upload/plugin.go @@ -5,13 +5,6 @@ package upload import ( - "context" - "embed" - "reflect" - - "github.com/gin-gonic/gin" - "github.com/hibiken/asynq" - "Wavelet/core" "Wavelet/core/contracts" "Wavelet/core/extpoints" @@ -19,6 +12,12 @@ import ( "Wavelet/plugins/domain/upload/handler" "Wavelet/plugins/domain/upload/shared" "Wavelet/plugins/domain/upload/task" + "context" + "embed" + "reflect" + + "github.com/gin-gonic/gin" + "github.com/hibiken/asynq" ) //go:embed migrations/*/*.sql diff --git a/backend/plugins/domain/upload/repository.go b/backend/plugins/domain/upload/repository.go index bebb7cb7..e772410f 100644 --- a/backend/plugins/domain/upload/repository.go +++ b/backend/plugins/domain/upload/repository.go @@ -4,14 +4,13 @@ package upload import ( + "Wavelet/pkg/idgen" + "Wavelet/pkg/util" + "Wavelet/plugins/domain/upload/shared" "context" "strings" "gorm.io/gorm" - - "Wavelet/pkg/idgen" - "Wavelet/pkg/util" - "Wavelet/plugins/domain/upload/shared" ) // UploadListFilter filters paginated upload queries. diff --git a/backend/plugins/domain/upload/repository/repository.go b/backend/plugins/domain/upload/repository/repository.go index a1b5ff06..b7e8432f 100644 --- a/backend/plugins/domain/upload/repository/repository.go +++ b/backend/plugins/domain/upload/repository/repository.go @@ -5,14 +5,13 @@ package repository import ( + "Wavelet/pkg/util" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/shared" "context" "strings" "gorm.io/gorm" - - "Wavelet/pkg/util" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/shared" ) // UploadListFilter filters paginated upload queries. diff --git a/backend/plugins/domain/upload/shared/constants.go b/backend/plugins/domain/upload/shared/constants.go index 2c58bcec..1a1a7466 100644 --- a/backend/plugins/domain/upload/shared/constants.go +++ b/backend/plugins/domain/upload/shared/constants.go @@ -7,8 +7,8 @@ package shared const ( MaxUploadSize = 32 * 1024 * 1024 // 32MB DetectContentBytes = 512 // http.DetectContentType 需要的最小字节数 - UploadDirPerm = 0755 // 上传目录权限 - UploadFilePerm = 0644 // 上传文件权限 + UploadDirPerm = 0o755 // 上传目录权限 + UploadFilePerm = 0o644 // 上传文件权限 ImageQualityLow = "low" ImageQualityMedium = "medium" ImageQualityHigh = "high" diff --git a/backend/plugins/domain/upload/shared/context_services.go b/backend/plugins/domain/upload/shared/context_services.go index 3cb0fac9..cb6c2415 100644 --- a/backend/plugins/domain/upload/shared/context_services.go +++ b/backend/plugins/domain/upload/shared/context_services.go @@ -4,13 +4,12 @@ package shared import ( + "Wavelet/core" + "Wavelet/core/contracts" "context" "sync" "gorm.io/gorm" - - "Wavelet/core" - "Wavelet/core/contracts" ) var ( diff --git a/backend/plugins/domain/upload/shared/test_helpers.go b/backend/plugins/domain/upload/shared/test_helpers.go index 8afc8fa6..1e00b815 100644 --- a/backend/plugins/domain/upload/shared/test_helpers.go +++ b/backend/plugins/domain/upload/shared/test_helpers.go @@ -4,6 +4,8 @@ package shared import ( + "Wavelet/core/contracts" + "Wavelet/pkg/testhelper" "bytes" "context" "crypto/sha256" @@ -20,9 +22,6 @@ import ( "github.com/gin-gonic/gin" "gorm.io/gorm" - - "Wavelet/core/contracts" - "Wavelet/pkg/testhelper" ) // MockDBService is a mock implementation of contracts.DBService for unit testing. @@ -130,8 +129,8 @@ func (m *MockStorageService) Put(_ context.Context, key string, body io.Reader, } m.objects[key] = data if strings.HasPrefix(key, "uploads/") { - _ = os.MkdirAll(filepath.Dir(key), 0755) - _ = os.WriteFile(key, data, 0644) + _ = os.MkdirAll(filepath.Dir(key), 0o755) + _ = os.WriteFile(key, data, 0o644) } return contracts.StoragePutResult{Key: key, Bucket: "test-bucket"}, nil } @@ -234,7 +233,7 @@ func (a *MockAuthService) VerifyToken(_ context.Context, token string) (*contrac } // Authenticate verifies credentials. -func (a *MockAuthService) Authenticate(_ context.Context, _ string, _ string) (*contracts.UserDTO, error) { +func (a *MockAuthService) Authenticate(_ context.Context, _, _ string) (*contracts.UserDTO, error) { return nil, nil } diff --git a/backend/plugins/domain/upload/stats/category.go b/backend/plugins/domain/upload/stats/category.go index 1cee11b6..9e38c128 100644 --- a/backend/plugins/domain/upload/stats/category.go +++ b/backend/plugins/domain/upload/stats/category.go @@ -5,9 +5,8 @@ package stats import ( - "strings" - "Wavelet/plugins/domain/upload/util" + "strings" ) const ( diff --git a/backend/plugins/domain/upload/stats/stats_counter.go b/backend/plugins/domain/upload/stats/stats_counter.go index 7d3fcf19..c312fd30 100644 --- a/backend/plugins/domain/upload/stats/stats_counter.go +++ b/backend/plugins/domain/upload/stats/stats_counter.go @@ -4,15 +4,14 @@ package stats import ( + "Wavelet/pkg/logger" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/shared" "context" "time" "gorm.io/gorm" "gorm.io/gorm/clause" - - "Wavelet/pkg/logger" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/shared" ) // ApplyUploadStatsAdd increments incremental stats for a newly active upload record. diff --git a/backend/plugins/domain/upload/stats/stats_counter_test.go b/backend/plugins/domain/upload/stats/stats_counter_test.go index 8df23d1b..d5e58d3e 100644 --- a/backend/plugins/domain/upload/stats/stats_counter_test.go +++ b/backend/plugins/domain/upload/stats/stats_counter_test.go @@ -4,15 +4,14 @@ package stats import ( + "Wavelet/pkg/testhelper" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/shared" "context" "testing" "time" "gorm.io/gorm" - - "Wavelet/pkg/testhelper" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/shared" ) type mockDBService struct { diff --git a/backend/plugins/domain/upload/storage/access_state.go b/backend/plugins/domain/upload/storage/access_state.go index dfcbd459..44526924 100644 --- a/backend/plugins/domain/upload/storage/access_state.go +++ b/backend/plugins/domain/upload/storage/access_state.go @@ -5,12 +5,11 @@ package storage import ( + "Wavelet/core/contracts" + "Wavelet/plugins/domain/upload/shared" "context" "sync" "time" - - "Wavelet/core/contracts" - "Wavelet/plugins/domain/upload/shared" ) // MigrationAccessState captures cached migration maintenance state. diff --git a/backend/plugins/domain/upload/storage/migration.go b/backend/plugins/domain/upload/storage/migration.go index bd860448..0f813a5b 100644 --- a/backend/plugins/domain/upload/storage/migration.go +++ b/backend/plugins/domain/upload/storage/migration.go @@ -4,6 +4,8 @@ package storage import ( + "Wavelet/core/contracts" + "Wavelet/plugins/domain/upload/shared" "context" "encoding/json" "errors" @@ -11,9 +13,6 @@ import ( "strings" "gorm.io/gorm" - - "Wavelet/core/contracts" - "Wavelet/plugins/domain/upload/shared" ) // StorageMigrationTask is the task name for storage migration. diff --git a/backend/plugins/domain/upload/storage/storage_ops.go b/backend/plugins/domain/upload/storage/storage_ops.go index 88f3e74f..9ffd2aec 100644 --- a/backend/plugins/domain/upload/storage/storage_ops.go +++ b/backend/plugins/domain/upload/storage/storage_ops.go @@ -4,13 +4,12 @@ package storage import ( - "context" - "errors" - "Wavelet/core/contracts" "Wavelet/pkg/logger" "Wavelet/plugins/domain/upload/models" "Wavelet/plugins/domain/upload/shared" + "context" + "errors" ) // ReadOnly checks if the storage system is in read-only maintenance mode. diff --git a/backend/plugins/domain/upload/task/cleanup.go b/backend/plugins/domain/upload/task/cleanup.go index 72de2bcc..3dd8abd3 100644 --- a/backend/plugins/domain/upload/task/cleanup.go +++ b/backend/plugins/domain/upload/task/cleanup.go @@ -5,6 +5,10 @@ package task import ( + "Wavelet/core/contracts" + "Wavelet/pkg/logger" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/shared" "context" "errors" "fmt" @@ -12,11 +16,8 @@ import ( "gorm.io/gorm" - "Wavelet/core/contracts" - "Wavelet/pkg/logger" uploadcache "Wavelet/plugins/domain/upload/cache" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/shared" + uploadstats "Wavelet/plugins/domain/upload/stats" uploadstorage "Wavelet/plugins/domain/upload/storage" ) diff --git a/backend/plugins/domain/upload/task/rebuild_stats.go b/backend/plugins/domain/upload/task/rebuild_stats.go index ca60007b..0c93b349 100644 --- a/backend/plugins/domain/upload/task/rebuild_stats.go +++ b/backend/plugins/domain/upload/task/rebuild_stats.go @@ -4,14 +4,14 @@ package task import ( - "context" - "errors" - "fmt" - "Wavelet/core/contracts" "Wavelet/pkg/logger" "Wavelet/plugins/domain/upload/models" "Wavelet/plugins/domain/upload/shared" + "context" + "errors" + "fmt" + uploadstats "Wavelet/plugins/domain/upload/stats" ) diff --git a/backend/plugins/domain/upload/task/rebuild_stats_test.go b/backend/plugins/domain/upload/task/rebuild_stats_test.go index 950cb770..8ece3f9e 100644 --- a/backend/plugins/domain/upload/task/rebuild_stats_test.go +++ b/backend/plugins/domain/upload/task/rebuild_stats_test.go @@ -4,12 +4,11 @@ package task import ( + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/shared" "context" "testing" "time" - - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/shared" ) func TestRebuildUploadStatsHandler_Execute(t *testing.T) { diff --git a/backend/plugins/domain/upload/task/storage_migration.go b/backend/plugins/domain/upload/task/storage_migration.go index c580af65..32dce1c6 100644 --- a/backend/plugins/domain/upload/task/storage_migration.go +++ b/backend/plugins/domain/upload/task/storage_migration.go @@ -4,6 +4,11 @@ package task import ( + "Wavelet/core/contracts" + "Wavelet/pkg/logger" + "Wavelet/pkg/util" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/shared" "context" "crypto/sha256" "encoding/hex" @@ -18,11 +23,6 @@ import ( "golang.org/x/sync/errgroup" - "Wavelet/core/contracts" - "Wavelet/pkg/logger" - "Wavelet/pkg/util" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/shared" uploadstats "Wavelet/plugins/domain/upload/stats" uploadstorage "Wavelet/plugins/domain/upload/storage" ) diff --git a/backend/plugins/domain/upload/task/storage_migration_task_test.go b/backend/plugins/domain/upload/task/storage_migration_task_test.go index 07dbe69a..e950246d 100644 --- a/backend/plugins/domain/upload/task/storage_migration_task_test.go +++ b/backend/plugins/domain/upload/task/storage_migration_task_test.go @@ -4,6 +4,9 @@ package task import ( + "Wavelet/core/contracts" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/shared" "context" "crypto/sha256" "encoding/hex" @@ -13,9 +16,6 @@ import ( "strings" "testing" - "Wavelet/core/contracts" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/shared" uploadstorage "Wavelet/plugins/domain/upload/storage" ) @@ -25,11 +25,11 @@ func TestMigrationHandlerExecute(t *testing.T) { sourceRoot := t.TempDir() sourcePath := filepath.Join(sourceRoot, "uploads", "test.txt") - if err := os.MkdirAll(filepath.Dir(sourcePath), 0755); err != nil { + if err := os.MkdirAll(filepath.Dir(sourcePath), 0o755); err != nil { t.Fatalf("MkdirAll(%q) returned error: %v", sourcePath, err) } const content = "storage migration" - if err := os.WriteFile(sourcePath, []byte(content), 0644); err != nil { + if err := os.WriteFile(sourcePath, []byte(content), 0o644); err != nil { t.Fatalf("WriteFile(%q) returned error: %v", sourcePath, err) } @@ -100,11 +100,11 @@ func TestMigrationHandlerExecuteWithHashValidation(t *testing.T) { sourceRoot := t.TempDir() sourcePath := filepath.Join(sourceRoot, "uploads", "test-hash.txt") - if err := os.MkdirAll(filepath.Dir(sourcePath), 0755); err != nil { + if err := os.MkdirAll(filepath.Dir(sourcePath), 0o755); err != nil { t.Fatalf("MkdirAll(%q) returned error: %v", sourcePath, err) } const content = "storage migration integrity check content" - if err := os.WriteFile(sourcePath, []byte(content), 0644); err != nil { + if err := os.WriteFile(sourcePath, []byte(content), 0o644); err != nil { t.Fatalf("WriteFile(%q) returned error: %v", sourcePath, err) } diff --git a/backend/plugins/domain/upload/task/tasks.go b/backend/plugins/domain/upload/task/tasks.go index 2dcd9c50..c9082727 100644 --- a/backend/plugins/domain/upload/task/tasks.go +++ b/backend/plugins/domain/upload/task/tasks.go @@ -4,18 +4,17 @@ package task import ( + "Wavelet/core/contracts" + "Wavelet/pkg/logger" + "Wavelet/plugins/domain/upload/filesrv" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/shared" "context" "encoding/json" "errors" "fmt" "strings" "sync" - - "Wavelet/core/contracts" - "Wavelet/pkg/logger" - "Wavelet/plugins/domain/upload/filesrv" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/shared" ) const ( diff --git a/backend/plugins/domain/upload/task/tasks_test.go b/backend/plugins/domain/upload/task/tasks_test.go index 2ab98e70..df908a3e 100644 --- a/backend/plugins/domain/upload/task/tasks_test.go +++ b/backend/plugins/domain/upload/task/tasks_test.go @@ -4,6 +4,9 @@ package task import ( + "Wavelet/plugins/domain/upload/filesrv" + "Wavelet/plugins/domain/upload/models" + "Wavelet/plugins/domain/upload/shared" "bytes" "context" "encoding/json" @@ -17,10 +20,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/plugins/domain/upload/filesrv" - "Wavelet/plugins/domain/upload/models" - "Wavelet/plugins/domain/upload/shared" ) func TestSystemCleanupHandler_Execute(t *testing.T) { diff --git a/backend/plugins/domain/upload/util/media.go b/backend/plugins/domain/upload/util/media.go index cade8694..7b7274bd 100644 --- a/backend/plugins/domain/upload/util/media.go +++ b/backend/plugins/domain/upload/util/media.go @@ -4,9 +4,8 @@ package util import ( - "strings" - "Wavelet/plugins/domain/upload/shared" + "strings" ) // IsImageExtension reports whether ext is a common image format. diff --git a/backend/plugins/domain/upload/util/utils.go b/backend/plugins/domain/upload/util/utils.go index 0ce6fd1f..54887214 100644 --- a/backend/plugins/domain/upload/util/utils.go +++ b/backend/plugins/domain/upload/util/utils.go @@ -5,20 +5,19 @@ package util import ( + "Wavelet/plugins/domain/upload/shared" "bytes" "errors" "fmt" - "image" - _ "image/gif" // Register GIF decoder for image.Decode - _ "image/jpeg" // Register JPEG decoder for image.Decode - _ "image/png" // Register PNG decoder for image.Decode + "image" // Register GIF decoder for image.Decode + _ "image/gif" // Register JPEG decoder for image.Decode + _ "image/jpeg" // Register PNG decoder for image.Decode + _ "image/png" "io" "strings" "github.com/deepteams/webp" _ "golang.org/x/image/webp" // Register WebP decoder for image.Decode - - "Wavelet/plugins/domain/upload/shared" ) // ValidateS3Key validates an S3 object key for safety. diff --git a/backend/plugins/domain/user/handlers.go b/backend/plugins/domain/user/handlers.go index 163d65aa..0cfc03ef 100644 --- a/backend/plugins/domain/user/handlers.go +++ b/backend/plugins/domain/user/handlers.go @@ -4,6 +4,8 @@ package user import ( + "Wavelet/core/contracts" + "Wavelet/pkg/response" "context" "crypto/rand" "crypto/sha256" @@ -14,9 +16,6 @@ import ( "github.com/gin-contrib/sessions" "github.com/gin-gonic/gin" - - "Wavelet/core/contracts" - "Wavelet/pkg/response" ) type loginRequest struct { diff --git a/backend/plugins/domain/user/models.go b/backend/plugins/domain/user/models.go index 368d6bf1..f35df7ab 100644 --- a/backend/plugins/domain/user/models.go +++ b/backend/plugins/domain/user/models.go @@ -4,12 +4,10 @@ package user import ( + "Wavelet/pkg/util" "errors" - "strings" "time" - - "Wavelet/pkg/util" ) // AccessToken 个人访问令牌实体 diff --git a/backend/plugins/domain/user/plugin.go b/backend/plugins/domain/user/plugin.go index af17d090..f07f25c3 100644 --- a/backend/plugins/domain/user/plugin.go +++ b/backend/plugins/domain/user/plugin.go @@ -5,16 +5,15 @@ package user import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/core/extpoints" "context" "embed" "reflect" "github.com/gin-gonic/gin" "github.com/hibiken/asynq" - - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/core/extpoints" ) //go:embed migrations/*/*.sql diff --git a/backend/plugins/domain/user/plugin_test.go b/backend/plugins/domain/user/plugin_test.go index fc30d164..9bab4c53 100644 --- a/backend/plugins/domain/user/plugin_test.go +++ b/backend/plugins/domain/user/plugin_test.go @@ -4,6 +4,9 @@ package user_test import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/plugins/domain/user" "context" "path/filepath" "testing" @@ -13,9 +16,6 @@ import ( "github.com/stretchr/testify/require" "gorm.io/gorm" - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/plugins/domain/user" database "Wavelet/plugins/infra/database" ) diff --git a/backend/plugins/domain/user/repository.go b/backend/plugins/domain/user/repository.go index f0192178..338110bc 100644 --- a/backend/plugins/domain/user/repository.go +++ b/backend/plugins/domain/user/repository.go @@ -4,15 +4,14 @@ package user import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/pkg/util" "context" "strings" "sync" "gorm.io/gorm" - - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/pkg/util" ) var ( diff --git a/backend/plugins/domain/user/service.go b/backend/plugins/domain/user/service.go index 5d793c30..5cd15312 100644 --- a/backend/plugins/domain/user/service.go +++ b/backend/plugins/domain/user/service.go @@ -5,6 +5,9 @@ package user import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/pkg/idgen" "context" "errors" "fmt" @@ -13,10 +16,6 @@ import ( "gorm.io/gorm" - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/pkg/idgen" - pkgu "Wavelet/pkg/util" ) diff --git a/backend/plugins/drivers/driver_asynq_cron/db_helper.go b/backend/plugins/drivers/driver_asynq_cron/db_helper.go index 385dc045..b4f5c7b2 100644 --- a/backend/plugins/drivers/driver_asynq_cron/db_helper.go +++ b/backend/plugins/drivers/driver_asynq_cron/db_helper.go @@ -4,13 +4,12 @@ package driver_asynq_cron import ( + "Wavelet/core" + "Wavelet/core/contracts" "context" "sync" "gorm.io/gorm" - - "Wavelet/core" - "Wavelet/core/contracts" ) var ( diff --git a/backend/plugins/drivers/driver_asynq_cron/plugin.go b/backend/plugins/drivers/driver_asynq_cron/plugin.go index a8ffd150..8823e46a 100644 --- a/backend/plugins/drivers/driver_asynq_cron/plugin.go +++ b/backend/plugins/drivers/driver_asynq_cron/plugin.go @@ -5,6 +5,9 @@ package driver_asynq_cron import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/pkg/config" "context" "embed" "encoding/json" @@ -13,10 +16,6 @@ import ( "time" "github.com/hibiken/asynq" - - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/pkg/config" ) //go:embed migrations/*/*.sql diff --git a/backend/plugins/drivers/driver_asynq_cron/scheduler.go b/backend/plugins/drivers/driver_asynq_cron/scheduler.go index afc74080..1841b5cc 100644 --- a/backend/plugins/drivers/driver_asynq_cron/scheduler.go +++ b/backend/plugins/drivers/driver_asynq_cron/scheduler.go @@ -4,6 +4,8 @@ package driver_asynq_cron import ( + "Wavelet/core/contracts" + "Wavelet/pkg/logger" "context" "fmt" "os/signal" @@ -12,9 +14,6 @@ import ( "time" "github.com/hibiken/asynq" - - "Wavelet/core/contracts" - "Wavelet/pkg/logger" ) var ( @@ -153,7 +152,7 @@ func ReloadScheduler() error { return nil } -func waitForStop(done <-chan struct{}, signals <-chan struct{}) bool { +func waitForStop(done, signals <-chan struct{}) bool { select { case <-done: return false diff --git a/backend/plugins/drivers/driver_asynq_worker/db_helper.go b/backend/plugins/drivers/driver_asynq_worker/db_helper.go index 0660debd..025fbca1 100644 --- a/backend/plugins/drivers/driver_asynq_worker/db_helper.go +++ b/backend/plugins/drivers/driver_asynq_worker/db_helper.go @@ -4,14 +4,13 @@ package driver_asynq_worker import ( + "Wavelet/core" + "Wavelet/core/contracts" "context" "sync" "github.com/redis/go-redis/v9" "gorm.io/gorm" - - "Wavelet/core" - "Wavelet/core/contracts" ) var ( diff --git a/backend/plugins/drivers/driver_asynq_worker/executor.go b/backend/plugins/drivers/driver_asynq_worker/executor.go index c1776aea..3bd95dfc 100644 --- a/backend/plugins/drivers/driver_asynq_worker/executor.go +++ b/backend/plugins/drivers/driver_asynq_worker/executor.go @@ -4,6 +4,9 @@ package driver_asynq_worker import ( + "Wavelet/pkg/idgen" + "Wavelet/pkg/logger" + "Wavelet/pkg/util" "context" "encoding/json" "errors" @@ -18,10 +21,7 @@ import ( "go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/trace" - "Wavelet/pkg/idgen" - "Wavelet/pkg/logger" otel_trace "Wavelet/pkg/trace" - "Wavelet/pkg/util" ) var ( @@ -76,8 +76,10 @@ func ValidateAndNormalizePayload(asynqTaskType string, payload []byte) ([]byte, // contextKey 用于 context 存取 taskID type contextKey string -const taskIDKey contextKey = "task_execution_task_id" -const traceEnvelopeVersion = 1 +const ( + taskIDKey contextKey = "task_execution_task_id" + traceEnvelopeVersion = 1 +) type traceEnvelope struct { WaveletTraceEnvelope bool `json:"_wavelet_trace_envelope"` @@ -489,7 +491,7 @@ func handleSuccessfulTask(ctx context.Context, execution *TaskExecution, t *asyn } // generateTaskID 生成任务 ID -func generateTaskID(taskType string, triggeredBy string) string { +func generateTaskID(taskType, triggeredBy string) string { return fmt.Sprintf("%s_%s_%d", triggeredBy, taskType, idgen.NextUint64ID()) } diff --git a/backend/plugins/drivers/driver_asynq_worker/executor_test.go b/backend/plugins/drivers/driver_asynq_worker/executor_test.go index 30648028..23db8f0a 100644 --- a/backend/plugins/drivers/driver_asynq_worker/executor_test.go +++ b/backend/plugins/drivers/driver_asynq_worker/executor_test.go @@ -4,6 +4,7 @@ package driver_asynq_worker import ( + "Wavelet/pkg/testhelper" "context" "errors" "fmt" @@ -19,8 +20,6 @@ import ( "github.com/redis/go-redis/v9" "gorm.io/gorm" - - "Wavelet/pkg/testhelper" ) type mockDBService struct { diff --git a/backend/plugins/drivers/driver_asynq_worker/meta.go b/backend/plugins/drivers/driver_asynq_worker/meta.go index 620fb304..39fb85b5 100644 --- a/backend/plugins/drivers/driver_asynq_worker/meta.go +++ b/backend/plugins/drivers/driver_asynq_worker/meta.go @@ -4,9 +4,8 @@ package driver_asynq_worker import ( - "sync" - "Wavelet/core/extpoints" + "sync" ) // TaskParam 任务参数定义 diff --git a/backend/plugins/drivers/driver_asynq_worker/plugin.go b/backend/plugins/drivers/driver_asynq_worker/plugin.go index 5dc3dc07..b702aed9 100644 --- a/backend/plugins/drivers/driver_asynq_worker/plugin.go +++ b/backend/plugins/drivers/driver_asynq_worker/plugin.go @@ -5,6 +5,8 @@ package driver_asynq_worker import ( + "Wavelet/core" + "Wavelet/core/contracts" "context" "embed" "errors" @@ -14,9 +16,6 @@ import ( "github.com/hibiken/asynq" "github.com/redis/go-redis/v9" - - "Wavelet/core" - "Wavelet/core/contracts" ) const ( @@ -345,7 +344,7 @@ func (s *taskServiceImpl) GetTaskMeta(taskType string) (contracts.TaskMetaDTO, b }, true } -func (s *taskServiceImpl) ListExecutions(ctx context.Context, taskType string, status string, page, pageSize int) ([]contracts.TaskExecutionDTO, int64, error) { +func (s *taskServiceImpl) ListExecutions(ctx context.Context, taskType, status string, page, pageSize int) ([]contracts.TaskExecutionDTO, int64, error) { db := getDB(ctx) if db == nil { return nil, 0, errors.New("db not initialized") diff --git a/backend/plugins/drivers/driver_asynq_worker/task_repo.go b/backend/plugins/drivers/driver_asynq_worker/task_repo.go index b6739aba..26026bd6 100644 --- a/backend/plugins/drivers/driver_asynq_worker/task_repo.go +++ b/backend/plugins/drivers/driver_asynq_worker/task_repo.go @@ -4,6 +4,7 @@ package driver_asynq_worker import ( + "Wavelet/pkg/idgen" "context" "errors" "fmt" @@ -11,8 +12,6 @@ import ( "time" "github.com/redis/go-redis/v9" - - "Wavelet/pkg/idgen" ) const ( @@ -54,7 +53,7 @@ func getTaskExecutionByTaskID(ctx context.Context, taskID string) (*TaskExecutio return &execution, nil } -func appendTaskExecutionLog(ctx context.Context, taskID string, logLine string) error { +func appendTaskExecutionLog(ctx context.Context, taskID, logLine string) error { rdb := getRedisClient() if rdb == nil { return errors.New("redis client is not initialized") diff --git a/backend/plugins/drivers/driver_asynq_worker/utils.go b/backend/plugins/drivers/driver_asynq_worker/utils.go index fa275d6c..9e00beeb 100644 --- a/backend/plugins/drivers/driver_asynq_worker/utils.go +++ b/backend/plugins/drivers/driver_asynq_worker/utils.go @@ -4,13 +4,12 @@ package driver_asynq_worker import ( + "Wavelet/pkg/config" "sync" "github.com/hibiken/asynq" "github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9/maintnotifications" - - "Wavelet/pkg/config" ) type redisClientConnOpt struct { diff --git a/backend/plugins/drivers/driver_asynq_worker/utils_test.go b/backend/plugins/drivers/driver_asynq_worker/utils_test.go index e30b0162..b68a0672 100644 --- a/backend/plugins/drivers/driver_asynq_worker/utils_test.go +++ b/backend/plugins/drivers/driver_asynq_worker/utils_test.go @@ -4,11 +4,10 @@ package driver_asynq_worker import ( + "Wavelet/pkg/config" "testing" "github.com/redis/go-redis/v9/maintnotifications" - - "Wavelet/pkg/config" ) func TestMaintNotificationsConfig(t *testing.T) { diff --git a/backend/plugins/drivers/driver_http/db_helper.go b/backend/plugins/drivers/driver_http/db_helper.go index bd0b3c47..61ab5ac7 100644 --- a/backend/plugins/drivers/driver_http/db_helper.go +++ b/backend/plugins/drivers/driver_http/db_helper.go @@ -4,13 +4,12 @@ package driver_http import ( + "Wavelet/core" + "Wavelet/core/contracts" "context" "sync" "gorm.io/gorm" - - "Wavelet/core" - "Wavelet/core/contracts" ) var ( diff --git a/backend/plugins/drivers/driver_http/engine.go b/backend/plugins/drivers/driver_http/engine.go index c9414079..101de55e 100644 --- a/backend/plugins/drivers/driver_http/engine.go +++ b/backend/plugins/drivers/driver_http/engine.go @@ -4,6 +4,9 @@ package driver_http import ( + "Wavelet/pkg/config" + "Wavelet/pkg/trace" + "Wavelet/pkg/util" "context" "errors" "log" @@ -19,10 +22,6 @@ import ( "github.com/gin-contrib/sessions/redis" "github.com/gin-gonic/gin" "go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin" - - "Wavelet/pkg/config" - "Wavelet/pkg/trace" - "Wavelet/pkg/util" ) // BuildEngine 构建并初始化 Gin 路由引擎及全部中间件和路由 diff --git a/backend/plugins/drivers/driver_http/middlewares.go b/backend/plugins/drivers/driver_http/middlewares.go index 7bb6d3ec..b3de2ded 100644 --- a/backend/plugins/drivers/driver_http/middlewares.go +++ b/backend/plugins/drivers/driver_http/middlewares.go @@ -5,6 +5,9 @@ package driver_http import ( + "Wavelet/pkg/config" + "Wavelet/pkg/logger" + "Wavelet/pkg/response" "context" "net/http" "strconv" @@ -15,9 +18,6 @@ import ( "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" - "Wavelet/pkg/config" - "Wavelet/pkg/logger" - "Wavelet/pkg/response" otel_trace "Wavelet/pkg/trace" ) diff --git a/backend/plugins/drivers/driver_http/middlewares_test.go b/backend/plugins/drivers/driver_http/middlewares_test.go index cb3eb21f..739ec029 100644 --- a/backend/plugins/drivers/driver_http/middlewares_test.go +++ b/backend/plugins/drivers/driver_http/middlewares_test.go @@ -4,6 +4,7 @@ package driver_http import ( + "Wavelet/pkg/testhelper" "context" "net/http" "net/http/httptest" @@ -11,8 +12,6 @@ import ( "github.com/gin-gonic/gin" "gorm.io/gorm" - - "Wavelet/pkg/testhelper" ) type mockDBService struct { diff --git a/backend/plugins/drivers/driver_http/plugin.go b/backend/plugins/drivers/driver_http/plugin.go index fb088507..94ddcaba 100644 --- a/backend/plugins/drivers/driver_http/plugin.go +++ b/backend/plugins/drivers/driver_http/plugin.go @@ -5,6 +5,9 @@ package driver_http import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/pkg/util" "context" "errors" "fmt" @@ -14,10 +17,6 @@ import ( "time" "github.com/gin-gonic/gin" - - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/pkg/util" ) const ( diff --git a/backend/plugins/drivers/driver_inproc_cron/plugin.go b/backend/plugins/drivers/driver_inproc_cron/plugin.go index 2279b219..196af401 100644 --- a/backend/plugins/drivers/driver_inproc_cron/plugin.go +++ b/backend/plugins/drivers/driver_inproc_cron/plugin.go @@ -5,11 +5,10 @@ package driver_inproc_cron import ( - "context" - "sync" - "Wavelet/core" "Wavelet/core/contracts" + "context" + "sync" ) // Plugin implements core.Plugin and core.Driver for in-process cron job scheduling. diff --git a/backend/plugins/drivers/driver_inproc_cron/plugin_test.go b/backend/plugins/drivers/driver_inproc_cron/plugin_test.go index 09137b71..7a4fd7fb 100644 --- a/backend/plugins/drivers/driver_inproc_cron/plugin_test.go +++ b/backend/plugins/drivers/driver_inproc_cron/plugin_test.go @@ -4,6 +4,8 @@ package driver_inproc_cron_test import ( + "Wavelet/core" + "Wavelet/plugins/drivers/driver_inproc_cron" "context" "sync/atomic" "testing" @@ -11,9 +13,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/core" - "Wavelet/plugins/drivers/driver_inproc_cron" ) func TestInprocCronPlugin(t *testing.T) { diff --git a/backend/plugins/drivers/driver_inproc_cron/scheduler.go b/backend/plugins/drivers/driver_inproc_cron/scheduler.go index a8e23966..133c7b5c 100644 --- a/backend/plugins/drivers/driver_inproc_cron/scheduler.go +++ b/backend/plugins/drivers/driver_inproc_cron/scheduler.go @@ -4,6 +4,10 @@ package driver_inproc_cron import ( + "Wavelet/core/contracts" + "Wavelet/core/extpoints" + "Wavelet/pkg/logger" + "Wavelet/pkg/util" "context" "encoding/json" "errors" @@ -12,11 +16,6 @@ import ( "time" "github.com/robfig/cron/v3" - - "Wavelet/core/contracts" - "Wavelet/core/extpoints" - "Wavelet/pkg/logger" - "Wavelet/pkg/util" ) type inprocScheduler struct { diff --git a/backend/plugins/drivers/driver_inproc_worker/executor.go b/backend/plugins/drivers/driver_inproc_worker/executor.go index 6b3cb5d9..5f38a412 100644 --- a/backend/plugins/drivers/driver_inproc_worker/executor.go +++ b/backend/plugins/drivers/driver_inproc_worker/executor.go @@ -4,16 +4,15 @@ package driver_inproc_worker import ( + "Wavelet/core/extpoints" + "Wavelet/pkg/idgen" + "Wavelet/pkg/util" "context" "errors" "fmt" "sync" "sync/atomic" "time" - - "Wavelet/core/extpoints" - "Wavelet/pkg/idgen" - "Wavelet/pkg/util" ) const defaultRetryBackoff = 500 * time.Millisecond @@ -39,7 +38,7 @@ type InprocQueue struct { } // NewInprocQueue creates a new InprocQueue with a given concurrency and queue capacity. -func NewInprocQueue(concurrency int, queueCap int, taskReg extpoints.TaskExtension) *InprocQueue { +func NewInprocQueue(concurrency, queueCap int, taskReg extpoints.TaskExtension) *InprocQueue { if concurrency <= 0 { concurrency = 10 } diff --git a/backend/plugins/drivers/driver_inproc_worker/plugin.go b/backend/plugins/drivers/driver_inproc_worker/plugin.go index 7530735f..1ca152c0 100644 --- a/backend/plugins/drivers/driver_inproc_worker/plugin.go +++ b/backend/plugins/drivers/driver_inproc_worker/plugin.go @@ -5,12 +5,11 @@ package driver_inproc_worker import ( + "Wavelet/core" + "Wavelet/core/contracts" "context" "sync" "time" - - "Wavelet/core" - "Wavelet/core/contracts" ) const ( diff --git a/backend/plugins/drivers/driver_inproc_worker/plugin_test.go b/backend/plugins/drivers/driver_inproc_worker/plugin_test.go index 9e1450d5..42417d75 100644 --- a/backend/plugins/drivers/driver_inproc_worker/plugin_test.go +++ b/backend/plugins/drivers/driver_inproc_worker/plugin_test.go @@ -4,6 +4,9 @@ package driver_inproc_worker_test import ( + "Wavelet/core" + "Wavelet/core/extpoints" + "Wavelet/plugins/drivers/driver_inproc_worker" "context" "sync/atomic" "testing" @@ -11,10 +14,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/core" - "Wavelet/core/extpoints" - "Wavelet/plugins/drivers/driver_inproc_worker" ) func TestInprocWorkerPlugin(t *testing.T) { diff --git a/backend/plugins/drivers/driver_inproc_worker/task_service.go b/backend/plugins/drivers/driver_inproc_worker/task_service.go index 9726bf3c..687493ea 100644 --- a/backend/plugins/drivers/driver_inproc_worker/task_service.go +++ b/backend/plugins/drivers/driver_inproc_worker/task_service.go @@ -4,11 +4,10 @@ package driver_inproc_worker import ( - "context" - "fmt" - "Wavelet/core/contracts" "Wavelet/core/extpoints" + "context" + "fmt" ) type inprocTaskService struct { @@ -73,7 +72,7 @@ func (s *inprocTaskService) ReloadScheduler() error { func (s *inprocTaskService) AppendLog(_ context.Context, _ string, _ ...any) { } -func (s *inprocTaskService) ListExecutions(_ context.Context, _ string, _ string, _, _ int) ([]contracts.TaskExecutionDTO, int64, error) { +func (s *inprocTaskService) ListExecutions(_ context.Context, _, _ string, _, _ int) ([]contracts.TaskExecutionDTO, int64, error) { return []contracts.TaskExecutionDTO{}, 0, nil } diff --git a/backend/plugins/drivers/drivers_test.go b/backend/plugins/drivers/drivers_test.go index 062f1f63..340e2d2e 100644 --- a/backend/plugins/drivers/drivers_test.go +++ b/backend/plugins/drivers/drivers_test.go @@ -4,6 +4,11 @@ package drivers_test import ( + "Wavelet/core" + "Wavelet/core/extpoints" + "Wavelet/plugins/drivers/driver_asynq_cron" + "Wavelet/plugins/drivers/driver_asynq_worker" + "Wavelet/plugins/drivers/driver_http" "bytes" "context" "encoding/json" @@ -19,12 +24,6 @@ import ( "github.com/hibiken/asynq" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/core" - "Wavelet/core/extpoints" - "Wavelet/plugins/drivers/driver_asynq_cron" - "Wavelet/plugins/drivers/driver_asynq_worker" - "Wavelet/plugins/drivers/driver_http" ) func init() { diff --git a/backend/plugins/infra/cache/plugin.go b/backend/plugins/infra/cache/plugin.go index b330d09e..081011e9 100644 --- a/backend/plugins/infra/cache/plugin.go +++ b/backend/plugins/infra/cache/plugin.go @@ -5,6 +5,10 @@ package cache import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/pkg/cache/ram" + "Wavelet/pkg/util" "context" "encoding/json" "errors" @@ -12,11 +16,6 @@ import ( "time" "github.com/redis/go-redis/v9" - - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/pkg/cache/ram" - "Wavelet/pkg/util" ) const ( diff --git a/backend/plugins/infra/cache/plugin_test.go b/backend/plugins/infra/cache/plugin_test.go index 217d8795..e1cf4c67 100644 --- a/backend/plugins/infra/cache/plugin_test.go +++ b/backend/plugins/infra/cache/plugin_test.go @@ -4,6 +4,9 @@ package cache_test import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/plugins/infra/cache" "context" "testing" "time" @@ -12,10 +15,6 @@ import ( "github.com/redis/go-redis/v9" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/plugins/infra/cache" ) func TestCachePluginOperations(t *testing.T) { diff --git a/backend/plugins/infra/cache/redis.go b/backend/plugins/infra/cache/redis.go index 6580b3f5..56a5e1f9 100644 --- a/backend/plugins/infra/cache/redis.go +++ b/backend/plugins/infra/cache/redis.go @@ -4,6 +4,7 @@ package cache import ( + "Wavelet/pkg/config" "context" "encoding/json" "fmt" @@ -15,14 +16,10 @@ import ( "github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9/maintnotifications" "go.opentelemetry.io/otel/attribute" - - "Wavelet/pkg/config" ) -var ( - // Redis 全局 Redis 客户端实例 - Redis redis.UniversalClient -) +// Redis 全局 Redis 客户端实例 +var Redis redis.UniversalClient // InitRedis 初始化全局/默认 Redis 客户端实例 func InitRedis() (redis.UniversalClient, error) { diff --git a/backend/plugins/infra/cache_memory/cache.go b/backend/plugins/infra/cache_memory/cache.go index 9639975b..8ef9a499 100644 --- a/backend/plugins/infra/cache_memory/cache.go +++ b/backend/plugins/infra/cache_memory/cache.go @@ -4,13 +4,12 @@ package cache_memory import ( - "context" - "encoding/json" - "time" - "Wavelet/core" "Wavelet/core/contracts" "Wavelet/pkg/cache/ram" + "context" + "encoding/json" + "time" ) type ramEntry struct { diff --git a/backend/plugins/infra/cache_memory/plugin_test.go b/backend/plugins/infra/cache_memory/plugin_test.go index e8f27a1e..66c5fdba 100644 --- a/backend/plugins/infra/cache_memory/plugin_test.go +++ b/backend/plugins/infra/cache_memory/plugin_test.go @@ -4,16 +4,15 @@ package cache_memory_test import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/plugins/infra/cache_memory" "context" "testing" "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/plugins/infra/cache_memory" ) func TestCacheMemoryPlugin(t *testing.T) { diff --git a/backend/plugins/infra/database/clickhouse.go b/backend/plugins/infra/database/clickhouse.go index 82094fac..883b43d2 100644 --- a/backend/plugins/infra/database/clickhouse.go +++ b/backend/plugins/infra/database/clickhouse.go @@ -5,6 +5,7 @@ package database import ( + "Wavelet/pkg/config" "context" "fmt" "log" @@ -19,8 +20,6 @@ import ( clickhouseDriver "gorm.io/driver/clickhouse" "gorm.io/gorm" "gorm.io/plugin/opentelemetry/tracing" - - "Wavelet/pkg/config" ) const ( diff --git a/backend/plugins/infra/database/plugin.go b/backend/plugins/infra/database/plugin.go index eb0161b0..eca4c978 100644 --- a/backend/plugins/infra/database/plugin.go +++ b/backend/plugins/infra/database/plugin.go @@ -5,12 +5,11 @@ package database import ( + "Wavelet/core" + "Wavelet/core/contracts" "context" "gorm.io/gorm" - - "Wavelet/core" - "Wavelet/core/contracts" ) // Option configures the database plugin. diff --git a/backend/plugins/infra/database/plugin_test.go b/backend/plugins/infra/database/plugin_test.go index 4b42fb3e..8aa6861a 100644 --- a/backend/plugins/infra/database/plugin_test.go +++ b/backend/plugins/infra/database/plugin_test.go @@ -4,6 +4,9 @@ package database_test import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/plugins/infra/database" "context" "path/filepath" "testing" @@ -12,10 +15,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gorm.io/gorm" - - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/plugins/infra/database" ) type Item struct { diff --git a/backend/plugins/infra/database/postgres.go b/backend/plugins/infra/database/postgres.go index c6e689b2..96335918 100644 --- a/backend/plugins/infra/database/postgres.go +++ b/backend/plugins/infra/database/postgres.go @@ -4,6 +4,7 @@ package database import ( + "Wavelet/pkg/config" "context" "fmt" "log" @@ -21,13 +22,9 @@ import ( "gorm.io/gorm" "gorm.io/plugin/dbresolver" "gorm.io/plugin/opentelemetry/tracing" - - "Wavelet/pkg/config" ) -var ( - db *gorm.DB -) +var db *gorm.DB // InitDB 初始化主数据库实例(支持 PostgreSQL / SQLite) func InitDB() (*gorm.DB, error) { @@ -46,7 +43,7 @@ func initSQLite() (*gorm.DB, error) { if sqlitePath != ":memory:" && !strings.HasPrefix(sqlitePath, "file:") { if dir := filepath.Dir(sqlitePath); dir != "" && dir != "." { - if err := os.MkdirAll(dir, 0755); err != nil { + if err := os.MkdirAll(dir, 0o755); err != nil { return nil, fmt.Errorf("create sqlite directory %q failed: %w", dir, err) } } diff --git a/backend/plugins/infra/database/postgres_logger.go b/backend/plugins/infra/database/postgres_logger.go index 01f25f38..9652c2fb 100644 --- a/backend/plugins/infra/database/postgres_logger.go +++ b/backend/plugins/infra/database/postgres_logger.go @@ -4,6 +4,7 @@ package database import ( + "Wavelet/pkg/logger" "context" "errors" "fmt" @@ -12,8 +13,6 @@ import ( "gorm.io/gorm" gormLogger "gorm.io/gorm/logger" - - "Wavelet/pkg/logger" ) // nanoToMilli 纳秒转毫秒的除数 diff --git a/backend/plugins/infra/infra_test.go b/backend/plugins/infra/infra_test.go index 13c8fa54..568b10e6 100644 --- a/backend/plugins/infra/infra_test.go +++ b/backend/plugins/infra/infra_test.go @@ -4,6 +4,13 @@ package infra_test import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/plugins/infra/cache" + "Wavelet/plugins/infra/database" + "Wavelet/plugins/infra/logger" + "Wavelet/plugins/infra/storage" + "Wavelet/plugins/infra/storage/objectstore" "bytes" "context" "io" @@ -18,14 +25,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gorm.io/gorm" - - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/plugins/infra/cache" - "Wavelet/plugins/infra/database" - "Wavelet/plugins/infra/logger" - "Wavelet/plugins/infra/storage" - "Wavelet/plugins/infra/storage/objectstore" ) type TestUser struct { diff --git a/backend/plugins/infra/logger/plugin.go b/backend/plugins/infra/logger/plugin.go index e7e3ecbb..e97d540d 100644 --- a/backend/plugins/infra/logger/plugin.go +++ b/backend/plugins/infra/logger/plugin.go @@ -5,13 +5,12 @@ package logger import ( - "context" - "fmt" - "strings" - "Wavelet/core" "Wavelet/core/contracts" "Wavelet/pkg/logger" + "context" + "fmt" + "strings" ) // Plugin implements core.Plugin to provide contracts.LoggerService. diff --git a/backend/plugins/infra/logger/plugin_test.go b/backend/plugins/infra/logger/plugin_test.go index a2a3d28d..701967f1 100644 --- a/backend/plugins/infra/logger/plugin_test.go +++ b/backend/plugins/infra/logger/plugin_test.go @@ -4,15 +4,14 @@ package logger_test import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/plugins/infra/logger" "context" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/plugins/infra/logger" ) func TestLoggerPluginOperations(t *testing.T) { diff --git a/backend/plugins/infra/storage/diskcache/cache_test.go b/backend/plugins/infra/storage/diskcache/cache_test.go index 03a24f12..79f04eaa 100644 --- a/backend/plugins/infra/storage/diskcache/cache_test.go +++ b/backend/plugins/infra/storage/diskcache/cache_test.go @@ -4,12 +4,11 @@ package diskcache import ( + "Wavelet/pkg/testhelper" "context" "testing" "gorm.io/gorm" - - "Wavelet/pkg/testhelper" ) type mockDBService struct { diff --git a/backend/plugins/infra/storage/diskcache/db_helper.go b/backend/plugins/infra/storage/diskcache/db_helper.go index 1883295a..1a89378f 100644 --- a/backend/plugins/infra/storage/diskcache/db_helper.go +++ b/backend/plugins/infra/storage/diskcache/db_helper.go @@ -4,13 +4,12 @@ package diskcache import ( + "Wavelet/core" + "Wavelet/core/contracts" "context" "sync" "gorm.io/gorm" - - "Wavelet/core" - "Wavelet/core/contracts" ) var ( diff --git a/backend/plugins/infra/storage/objectstore/db_helper.go b/backend/plugins/infra/storage/objectstore/db_helper.go index ad47140c..73e67567 100644 --- a/backend/plugins/infra/storage/objectstore/db_helper.go +++ b/backend/plugins/infra/storage/objectstore/db_helper.go @@ -4,13 +4,12 @@ package objectstore import ( + "Wavelet/core" + "Wavelet/core/contracts" "context" "sync" "gorm.io/gorm" - - "Wavelet/core" - "Wavelet/core/contracts" ) var ( diff --git a/backend/plugins/infra/storage/objectstore/http.go b/backend/plugins/infra/storage/objectstore/http.go index b1555191..d2459741 100644 --- a/backend/plugins/infra/storage/objectstore/http.go +++ b/backend/plugins/infra/storage/objectstore/http.go @@ -4,13 +4,12 @@ package objectstore import ( + "Wavelet/pkg/httppool" "context" "fmt" "net/http" "net/url" "time" - - "Wavelet/pkg/httppool" ) func getHTTPObject(ctx context.Context, baseURL, key string) (*Object, error) { diff --git a/backend/plugins/infra/storage/objectstore/webdav.go b/backend/plugins/infra/storage/objectstore/webdav.go index e90aa634..8e270101 100644 --- a/backend/plugins/infra/storage/objectstore/webdav.go +++ b/backend/plugins/infra/storage/objectstore/webdav.go @@ -4,6 +4,7 @@ package objectstore import ( + "Wavelet/pkg/httppool" "context" "fmt" "io" @@ -12,8 +13,6 @@ import ( "strings" "github.com/studio-b12/gowebdav" - - "Wavelet/pkg/httppool" ) type contextTransport struct { diff --git a/backend/plugins/infra/storage/plugin.go b/backend/plugins/infra/storage/plugin.go index ac5734ef..3cd105af 100644 --- a/backend/plugins/infra/storage/plugin.go +++ b/backend/plugins/infra/storage/plugin.go @@ -5,15 +5,14 @@ package storage import ( - "context" - "errors" - "fmt" - "io" - "Wavelet/core" "Wavelet/core/contracts" "Wavelet/plugins/infra/storage/diskcache" "Wavelet/plugins/infra/storage/objectstore" + "context" + "errors" + "fmt" + "io" ) // Option configures the storage plugin. diff --git a/backend/plugins/infra/storage/plugin_test.go b/backend/plugins/infra/storage/plugin_test.go index 44b0614d..ebb54a20 100644 --- a/backend/plugins/infra/storage/plugin_test.go +++ b/backend/plugins/infra/storage/plugin_test.go @@ -4,6 +4,10 @@ package storage_test import ( + "Wavelet/core" + "Wavelet/core/contracts" + "Wavelet/plugins/infra/storage" + "Wavelet/plugins/infra/storage/objectstore" "bytes" "context" "errors" @@ -13,11 +17,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "Wavelet/core" - "Wavelet/core/contracts" - "Wavelet/plugins/infra/storage" - "Wavelet/plugins/infra/storage/objectstore" ) type mockStorageBackend struct {