Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion core/core.go → core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 0 additions & 25 deletions core/runtime.go

This file was deleted.

4 changes: 2 additions & 2 deletions core/core_test.go → core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion e/e.go → e.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion e/e_test.go → e_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package e
package core

import (
"errors"
Expand Down
3 changes: 0 additions & 3 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ go 1.25

use (
.
./cmd/core
./cmd/core-gui
./cmd/examples/core-static-di
)
File renamed without changes.
25 changes: 25 additions & 0 deletions runtime.go
Original file line number Diff line number Diff line change
@@ -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()
}
17 changes: 8 additions & 9 deletions runtime/runtime.go → runtime_pkg.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package runtime
package core

import (
"context"
"fmt"

"github.com/Snider/Core/core"
"github.com/wailsapp/wails/v3/pkg/application"
)

// Runtime is the container that holds all instantiated services.
// 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.
Expand All @@ -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{} {
Expand All @@ -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
}
Expand All @@ -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{})
}

Expand Down
19 changes: 9 additions & 10 deletions runtime/runtime_test.go → runtime_pkg_test.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
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)
},
},
{
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)
Expand All @@ -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)
Expand Down
Loading