From 8b7dc42b0d5e691d5a88f5bec854a47a1e3c6eb9 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 13 Nov 2025 18:47:00 +0000 Subject: [PATCH] refactor: Flatten repository structure - Move Go files from core, e, and runtime directories to the project root. - Unify package declarations to a single 'core' package. - Update go.work to exclude the cmd directory from the main build. - Resolve naming conflicts and update import paths. - Fix tests to work with the new structure. --- core/actions.go => actions.go | 0 core/core.go => core.go | 2 +- core/runtime.go | 25 ------------------- core/core_test.go => core_test.go | 4 +-- e/e.go => e.go | 2 +- e/e_test.go => e_test.go | 2 +- go.work | 3 --- core/interfaces.go => interfaces.go | 0 runtime.go | 25 +++++++++++++++++++ runtime/runtime.go => runtime_pkg.go | 17 ++++++------- .../runtime_test.go => runtime_pkg_test.go | 19 +++++++------- 11 files changed, 47 insertions(+), 52 deletions(-) rename core/actions.go => actions.go (100%) rename core/core.go => core.go (99%) delete mode 100644 core/runtime.go rename core/core_test.go => core_test.go (98%) rename e/e.go => e.go (99%) rename e/e_test.go => e_test.go (98%) rename core/interfaces.go => interfaces.go (100%) create mode 100644 runtime.go rename runtime/runtime.go => runtime_pkg.go (81%) rename runtime/runtime_test.go => runtime_pkg_test.go (65%) diff --git a/core/actions.go b/actions.go similarity index 100% rename from core/actions.go rename to actions.go diff --git a/core/core.go b/core.go similarity index 99% rename from core/core.go rename to core.go index a708117..685147e 100644 --- a/core/core.go +++ b/core.go @@ -52,7 +52,7 @@ func WithService(factory func(*Core) (any, error)) Option { } pkgPath := typeOfService.PkgPath() parts := strings.Split(pkgPath, "/") - name := parts[len(parts)-1] + name := strings.ToLower(parts[len(parts)-1]) // --- IPC Handler Discovery --- instanceValue := reflect.ValueOf(serviceInstance) diff --git a/core/runtime.go b/core/runtime.go deleted file mode 100644 index 539ec1f..0000000 --- a/core/runtime.go +++ /dev/null @@ -1,25 +0,0 @@ -package core - -// Runtime is a helper struct embedded in services to provide access to the core application. -type Runtime[T any] struct { - core *Core - opts T -} - -// NewRuntime creates a new Runtime instance for a service. -func NewRuntime[T any](c *Core, opts T) *Runtime[T] { - return &Runtime[T]{ - core: c, - opts: opts, - } -} - -// Core returns the central core instance. -func (r *Runtime[T]) Core() *Core { - return r.core -} - -// Config returns the registered Config service from the core application. -func (r *Runtime[T]) Config() Config { - return r.core.Config() -} diff --git a/core/core_test.go b/core_test.go similarity index 98% rename from core/core_test.go rename to core_test.go index bab401b..fa1ee6a 100644 --- a/core/core_test.go +++ b/core_test.go @@ -53,14 +53,14 @@ func TestCore_WithWails_Good(t *testing.T) { assert.Equal(t, app, c.App) } -//go:embed testdata +//go:embed core/testdata var testFS embed.FS func TestCore_WithAssets_Good(t *testing.T) { c, err := New(WithAssets(testFS)) assert.NoError(t, err) assets := c.Assets() - file, err := assets.Open("testdata/test.txt") + file, err := assets.Open("core/testdata/test.txt") assert.NoError(t, err) defer file.Close() content, err := io.ReadAll(file) diff --git a/e/e.go b/e.go similarity index 99% rename from e/e.go rename to e.go index bfe9a08..d167c2f 100644 --- a/e/e.go +++ b/e.go @@ -13,7 +13,7 @@ // that is more informative than a raw stack trace. // - Consistent error handling: Encourages a uniform approach to error // handling across the entire codebase. -package e +package core import ( "fmt" diff --git a/e/e_test.go b/e_test.go similarity index 98% rename from e/e_test.go rename to e_test.go index 54cf772..71b04c0 100644 --- a/e/e_test.go +++ b/e_test.go @@ -1,4 +1,4 @@ -package e +package core import ( "errors" diff --git a/go.work b/go.work index 1b7697a..912f29e 100644 --- a/go.work +++ b/go.work @@ -2,7 +2,4 @@ go 1.25 use ( . - ./cmd/core - ./cmd/core-gui - ./cmd/examples/core-static-di ) diff --git a/core/interfaces.go b/interfaces.go similarity index 100% rename from core/interfaces.go rename to interfaces.go diff --git a/runtime.go b/runtime.go new file mode 100644 index 0000000..a444f6f --- /dev/null +++ b/runtime.go @@ -0,0 +1,25 @@ +package core + +// ServiceRuntime is a helper struct embedded in services to provide access to the core application. +type ServiceRuntime[T any] struct { + core *Core + opts T +} + +// NewServiceRuntime creates a new ServiceRuntime instance for a service. +func NewServiceRuntime[T any](c *Core, opts T) *ServiceRuntime[T] { + return &ServiceRuntime[T]{ + core: c, + opts: opts, + } +} + +// Core returns the central core instance. +func (r *ServiceRuntime[T]) Core() *Core { + return r.core +} + +// Config returns the registered Config service from the core application. +func (r *ServiceRuntime[T]) Config() Config { + return r.core.Config() +} diff --git a/runtime/runtime.go b/runtime_pkg.go similarity index 81% rename from runtime/runtime.go rename to runtime_pkg.go index 7a0a194..ee0913b 100644 --- a/runtime/runtime.go +++ b/runtime_pkg.go @@ -1,10 +1,9 @@ -package runtime +package core import ( "context" "fmt" - "github.com/Snider/Core/core" "github.com/wailsapp/wails/v3/pkg/application" ) @@ -12,7 +11,7 @@ import ( // Its fields are the concrete types, allowing Wails to bind them directly. type Runtime struct { app *application.App - Core *core.Core + Core *Core } // ServiceFactory defines a function that creates a service instance. @@ -21,8 +20,8 @@ type ServiceFactory func() (any, error) // NewWithFactories creates a new Runtime instance using the provided service factories. func NewWithFactories(app *application.App, factories map[string]ServiceFactory) (*Runtime, error) { services := make(map[string]any) - coreOpts := []core.Option{ - core.WithWails(app), + coreOpts := []Option{ + WithWails(app), } for _, name := range []string{} { @@ -36,10 +35,10 @@ func NewWithFactories(app *application.App, factories map[string]ServiceFactory) } services[name] = svc svcCopy := svc - coreOpts = append(coreOpts, core.WithName(name, func(c *core.Core) (any, error) { return svcCopy, nil })) + coreOpts = append(coreOpts, WithName(name, func(c *Core) (any, error) { return svcCopy, nil })) } - coreInstance, err := core.New(coreOpts...) + coreInstance, err := New(coreOpts...) if err != nil { return nil, err } @@ -54,8 +53,8 @@ func NewWithFactories(app *application.App, factories map[string]ServiceFactory) return rt, nil } -// New creates and wires together all application services. -func New(app *application.App) (*Runtime, error) { +// NewRuntime creates and wires together all application services. +func NewRuntime(app *application.App) (*Runtime, error) { return NewWithFactories(app, map[string]ServiceFactory{}) } diff --git a/runtime/runtime_test.go b/runtime_pkg_test.go similarity index 65% rename from runtime/runtime_test.go rename to runtime_pkg_test.go index 3993329..9113003 100644 --- a/runtime/runtime_test.go +++ b/runtime_pkg_test.go @@ -1,28 +1,27 @@ -package runtime_test +package core import ( "testing" - "github.com/Snider/Core/runtime" "github.com/stretchr/testify/assert" "github.com/wailsapp/wails/v3/pkg/application" ) -func TestNew(t *testing.T) { +func TestNewRuntime(t *testing.T) { testCases := []struct { name string app *application.App - factories map[string]runtime.ServiceFactory + factories map[string]ServiceFactory expectErr bool expectErrStr string - checkRuntime func(*testing.T, *runtime.Runtime) + checkRuntime func(*testing.T, *Runtime) }{ { name: "Good path", app: nil, - factories: map[string]runtime.ServiceFactory{}, + factories: map[string]ServiceFactory{}, expectErr: false, - checkRuntime: func(t *testing.T, rt *runtime.Runtime) { + checkRuntime: func(t *testing.T, rt *Runtime) { assert.NotNil(t, rt) assert.NotNil(t, rt.Core) }, @@ -30,9 +29,9 @@ func TestNew(t *testing.T) { { name: "With non-nil app", app: &application.App{}, - factories: map[string]runtime.ServiceFactory{}, + factories: map[string]ServiceFactory{}, expectErr: false, - checkRuntime: func(t *testing.T, rt *runtime.Runtime) { + checkRuntime: func(t *testing.T, rt *Runtime) { assert.NotNil(t, rt) assert.NotNil(t, rt.Core) assert.NotNil(t, rt.Core.App) @@ -42,7 +41,7 @@ func TestNew(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - rt, err := runtime.NewWithFactories(tc.app, tc.factories) + rt, err := NewRuntime(tc.app) if tc.expectErr { assert.Error(t, err)