diff --git a/cmd/server/main.go b/cmd/server/main.go index 107877d..630c864 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -13,9 +13,9 @@ import ( "runtime" "syscall" - "git.netflux.io/rob/octoplex/internal/app" "git.netflux.io/rob/octoplex/internal/config" "git.netflux.io/rob/octoplex/internal/domain" + "git.netflux.io/rob/octoplex/internal/server" dockerclient "github.com/docker/docker/client" ) @@ -106,7 +106,7 @@ func run() error { return fmt.Errorf("new docker client: %w", err) } - app := app.New(app.Params{ + app := server.New(server.Params{ ConfigService: configService, DockerClient: dockerClient, ConfigFilePath: configService.Path(), diff --git a/go.mod b/go.mod index 81d5088..76ee69f 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/stretchr/testify v1.10.0 github.com/testcontainers/testcontainers-go v0.35.0 golang.design/x/clipboard v0.7.0 + golang.org/x/sync v0.13.0 google.golang.org/grpc v1.69.4 google.golang.org/protobuf v1.36.3 gopkg.in/yaml.v3 v3.0.1 @@ -98,7 +99,6 @@ require ( golang.org/x/mobile v0.0.0-20250408133729-978277e7eaf7 // indirect golang.org/x/mod v0.24.0 // indirect golang.org/x/net v0.39.0 // indirect - golang.org/x/sync v0.13.0 // indirect golang.org/x/sys v0.32.0 // indirect golang.org/x/term v0.31.0 // indirect golang.org/x/text v0.24.0 // indirect diff --git a/internal/client/clientapp.go b/internal/client/clientapp.go index eec1380..7cfa00b 100644 --- a/internal/client/clientapp.go +++ b/internal/client/clientapp.go @@ -3,13 +3,13 @@ package client import ( "context" "fmt" + "log/slog" "git.netflux.io/rob/octoplex/internal/domain" "git.netflux.io/rob/octoplex/internal/event" pb "git.netflux.io/rob/octoplex/internal/generated/grpc" "git.netflux.io/rob/octoplex/internal/protocol" "git.netflux.io/rob/octoplex/internal/terminal" - "github.com/sagikazarmark/slog-shim" "golang.org/x/sync/errgroup" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" diff --git a/internal/app/integration_helpers_test.go b/internal/client/integration_helpers_test.go similarity index 97% rename from internal/app/integration_helpers_test.go rename to internal/client/integration_helpers_test.go index e08b832..13d2fc5 100644 --- a/internal/app/integration_helpers_test.go +++ b/internal/client/integration_helpers_test.go @@ -1,6 +1,6 @@ //go:build integration -package app_test +package client_test import ( "context" @@ -15,11 +15,11 @@ import ( "testing" "time" - "git.netflux.io/rob/octoplex/internal/app" "git.netflux.io/rob/octoplex/internal/client" "git.netflux.io/rob/octoplex/internal/config" "git.netflux.io/rob/octoplex/internal/container" "git.netflux.io/rob/octoplex/internal/domain" + "git.netflux.io/rob/octoplex/internal/server" "git.netflux.io/rob/octoplex/internal/terminal" "github.com/gdamore/tcell/v2" "github.com/stretchr/testify/require" @@ -32,7 +32,7 @@ func buildClientServer( screen tcell.SimulationScreen, screenCaptureC chan<- terminal.ScreenCapture, logger *slog.Logger, -) (*client.App, *app.App) { +) (*client.App, *server.App) { client := client.New(client.NewParams{ BuildInfo: domain.BuildInfo{Version: "0.0.1", GoVersion: "go1.16.3"}, Screen: &terminal.Screen{ @@ -44,7 +44,7 @@ func buildClientServer( Logger: logger, }) - server := app.New(app.Params{ + server := server.New(server.Params{ ConfigService: configService, DockerClient: dockerClient, Logger: logger, @@ -62,7 +62,7 @@ func runClientServer( ctx context.Context, _ *testing.T, clientApp *client.App, - serverApp *app.App, + serverApp *server.App, ) <-chan clientServerResult { ch := make(chan clientServerResult, 1) diff --git a/internal/app/integration_test.go b/internal/client/integration_test.go similarity index 99% rename from internal/app/integration_test.go rename to internal/client/integration_test.go index df5e13b..51a5f62 100644 --- a/internal/app/integration_test.go +++ b/internal/client/integration_test.go @@ -1,6 +1,6 @@ //go:build integration -package app_test +package client_test import ( "cmp" diff --git a/internal/app/testdata/mediamtx.yml b/internal/client/testdata/mediamtx.yml similarity index 100% rename from internal/app/testdata/mediamtx.yml rename to internal/client/testdata/mediamtx.yml diff --git a/internal/app/testdata/openssl.cnf b/internal/client/testdata/openssl.cnf similarity index 100% rename from internal/app/testdata/openssl.cnf rename to internal/client/testdata/openssl.cnf diff --git a/internal/app/testdata/server.crt b/internal/client/testdata/server.crt similarity index 100% rename from internal/app/testdata/server.crt rename to internal/client/testdata/server.crt diff --git a/internal/app/testdata/server.key b/internal/client/testdata/server.key similarity index 100% rename from internal/app/testdata/server.key rename to internal/client/testdata/server.key diff --git a/internal/server/server.go b/internal/server/grpc.go similarity index 92% rename from internal/server/server.go rename to internal/server/grpc.go index 2ccfb54..b28bbf6 100644 --- a/internal/server/server.go +++ b/internal/server/grpc.go @@ -5,14 +5,16 @@ import ( "errors" "fmt" "io" + "log/slog" "git.netflux.io/rob/octoplex/internal/event" pb "git.netflux.io/rob/octoplex/internal/generated/grpc" "git.netflux.io/rob/octoplex/internal/protocol" - "github.com/sagikazarmark/slog-shim" "golang.org/x/sync/errgroup" ) +// Server is the gRPC server that handles incoming commands and outgoing +// events. type Server struct { pb.UnimplementedInternalAPIServer @@ -21,7 +23,8 @@ type Server struct { logger *slog.Logger } -func New( +// newServer creates a new gRPC server. +func newServer( dispatcher func(event.Command), bus *event.Bus, logger *slog.Logger, diff --git a/internal/app/app.go b/internal/server/serverapp.go similarity index 98% rename from internal/app/app.go rename to internal/server/serverapp.go index 720c6bf..ded01e8 100644 --- a/internal/app/app.go +++ b/internal/server/serverapp.go @@ -1,4 +1,4 @@ -package app +package server import ( "cmp" @@ -18,7 +18,6 @@ import ( pb "git.netflux.io/rob/octoplex/internal/generated/grpc" "git.netflux.io/rob/octoplex/internal/mediaserver" "git.netflux.io/rob/octoplex/internal/replicator" - "git.netflux.io/rob/octoplex/internal/server" "github.com/docker/docker/client" "google.golang.org/grpc" ) @@ -83,7 +82,7 @@ func (a *App) Run(ctx context.Context) error { grpcServer := grpc.NewServer() grpcDone := make(chan error, 1) - pb.RegisterInternalAPIServer(grpcServer, server.New(a.DispatchAsync, a.eventBus, a.logger)) + pb.RegisterInternalAPIServer(grpcServer, newServer(a.DispatchAsync, a.eventBus, a.logger)) go func() { a.logger.Info("gRPC server started", "addr", grpcAddr) grpcDone <- grpcServer.Serve(lis) diff --git a/internal/app/app_test.go b/internal/server/serverapp_test.go similarity index 99% rename from internal/app/app_test.go rename to internal/server/serverapp_test.go index c9985ef..5c74a39 100644 --- a/internal/app/app_test.go +++ b/internal/server/serverapp_test.go @@ -1,4 +1,4 @@ -package app +package server import ( "testing"