fixup! wip: refactor: API

This commit is contained in:
Rob Watson 2025-05-11 08:11:05 +02:00
parent c5724dfe59
commit 5aa1be2066
12 changed files with 18 additions and 16 deletions

View File

@ -13,9 +13,9 @@ import (
"runtime" "runtime"
"syscall" "syscall"
"git.netflux.io/rob/octoplex/internal/app"
"git.netflux.io/rob/octoplex/internal/config" "git.netflux.io/rob/octoplex/internal/config"
"git.netflux.io/rob/octoplex/internal/domain" "git.netflux.io/rob/octoplex/internal/domain"
"git.netflux.io/rob/octoplex/internal/server"
dockerclient "github.com/docker/docker/client" dockerclient "github.com/docker/docker/client"
) )
@ -106,7 +106,7 @@ func run() error {
return fmt.Errorf("new docker client: %w", err) return fmt.Errorf("new docker client: %w", err)
} }
app := app.New(app.Params{ app := server.New(server.Params{
ConfigService: configService, ConfigService: configService,
DockerClient: dockerClient, DockerClient: dockerClient,
ConfigFilePath: configService.Path(), ConfigFilePath: configService.Path(),

2
go.mod
View File

@ -12,6 +12,7 @@ require (
github.com/stretchr/testify v1.10.0 github.com/stretchr/testify v1.10.0
github.com/testcontainers/testcontainers-go v0.35.0 github.com/testcontainers/testcontainers-go v0.35.0
golang.design/x/clipboard v0.7.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/grpc v1.69.4
google.golang.org/protobuf v1.36.3 google.golang.org/protobuf v1.36.3
gopkg.in/yaml.v3 v3.0.1 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/mobile v0.0.0-20250408133729-978277e7eaf7 // indirect
golang.org/x/mod v0.24.0 // indirect golang.org/x/mod v0.24.0 // indirect
golang.org/x/net v0.39.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/sys v0.32.0 // indirect
golang.org/x/term v0.31.0 // indirect golang.org/x/term v0.31.0 // indirect
golang.org/x/text v0.24.0 // indirect golang.org/x/text v0.24.0 // indirect

View File

@ -3,13 +3,13 @@ package client
import ( import (
"context" "context"
"fmt" "fmt"
"log/slog"
"git.netflux.io/rob/octoplex/internal/domain" "git.netflux.io/rob/octoplex/internal/domain"
"git.netflux.io/rob/octoplex/internal/event" "git.netflux.io/rob/octoplex/internal/event"
pb "git.netflux.io/rob/octoplex/internal/generated/grpc" pb "git.netflux.io/rob/octoplex/internal/generated/grpc"
"git.netflux.io/rob/octoplex/internal/protocol" "git.netflux.io/rob/octoplex/internal/protocol"
"git.netflux.io/rob/octoplex/internal/terminal" "git.netflux.io/rob/octoplex/internal/terminal"
"github.com/sagikazarmark/slog-shim"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/credentials/insecure"

View File

@ -1,6 +1,6 @@
//go:build integration //go:build integration
package app_test package client_test
import ( import (
"context" "context"
@ -15,11 +15,11 @@ import (
"testing" "testing"
"time" "time"
"git.netflux.io/rob/octoplex/internal/app"
"git.netflux.io/rob/octoplex/internal/client" "git.netflux.io/rob/octoplex/internal/client"
"git.netflux.io/rob/octoplex/internal/config" "git.netflux.io/rob/octoplex/internal/config"
"git.netflux.io/rob/octoplex/internal/container" "git.netflux.io/rob/octoplex/internal/container"
"git.netflux.io/rob/octoplex/internal/domain" "git.netflux.io/rob/octoplex/internal/domain"
"git.netflux.io/rob/octoplex/internal/server"
"git.netflux.io/rob/octoplex/internal/terminal" "git.netflux.io/rob/octoplex/internal/terminal"
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -32,7 +32,7 @@ func buildClientServer(
screen tcell.SimulationScreen, screen tcell.SimulationScreen,
screenCaptureC chan<- terminal.ScreenCapture, screenCaptureC chan<- terminal.ScreenCapture,
logger *slog.Logger, logger *slog.Logger,
) (*client.App, *app.App) { ) (*client.App, *server.App) {
client := client.New(client.NewParams{ client := client.New(client.NewParams{
BuildInfo: domain.BuildInfo{Version: "0.0.1", GoVersion: "go1.16.3"}, BuildInfo: domain.BuildInfo{Version: "0.0.1", GoVersion: "go1.16.3"},
Screen: &terminal.Screen{ Screen: &terminal.Screen{
@ -44,7 +44,7 @@ func buildClientServer(
Logger: logger, Logger: logger,
}) })
server := app.New(app.Params{ server := server.New(server.Params{
ConfigService: configService, ConfigService: configService,
DockerClient: dockerClient, DockerClient: dockerClient,
Logger: logger, Logger: logger,
@ -62,7 +62,7 @@ func runClientServer(
ctx context.Context, ctx context.Context,
_ *testing.T, _ *testing.T,
clientApp *client.App, clientApp *client.App,
serverApp *app.App, serverApp *server.App,
) <-chan clientServerResult { ) <-chan clientServerResult {
ch := make(chan clientServerResult, 1) ch := make(chan clientServerResult, 1)

View File

@ -1,6 +1,6 @@
//go:build integration //go:build integration
package app_test package client_test
import ( import (
"cmp" "cmp"

View File

@ -5,14 +5,16 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"log/slog"
"git.netflux.io/rob/octoplex/internal/event" "git.netflux.io/rob/octoplex/internal/event"
pb "git.netflux.io/rob/octoplex/internal/generated/grpc" pb "git.netflux.io/rob/octoplex/internal/generated/grpc"
"git.netflux.io/rob/octoplex/internal/protocol" "git.netflux.io/rob/octoplex/internal/protocol"
"github.com/sagikazarmark/slog-shim"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
) )
// Server is the gRPC server that handles incoming commands and outgoing
// events.
type Server struct { type Server struct {
pb.UnimplementedInternalAPIServer pb.UnimplementedInternalAPIServer
@ -21,7 +23,8 @@ type Server struct {
logger *slog.Logger logger *slog.Logger
} }
func New( // newServer creates a new gRPC server.
func newServer(
dispatcher func(event.Command), dispatcher func(event.Command),
bus *event.Bus, bus *event.Bus,
logger *slog.Logger, logger *slog.Logger,

View File

@ -1,4 +1,4 @@
package app package server
import ( import (
"cmp" "cmp"
@ -18,7 +18,6 @@ import (
pb "git.netflux.io/rob/octoplex/internal/generated/grpc" pb "git.netflux.io/rob/octoplex/internal/generated/grpc"
"git.netflux.io/rob/octoplex/internal/mediaserver" "git.netflux.io/rob/octoplex/internal/mediaserver"
"git.netflux.io/rob/octoplex/internal/replicator" "git.netflux.io/rob/octoplex/internal/replicator"
"git.netflux.io/rob/octoplex/internal/server"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"google.golang.org/grpc" "google.golang.org/grpc"
) )
@ -83,7 +82,7 @@ func (a *App) Run(ctx context.Context) error {
grpcServer := grpc.NewServer() grpcServer := grpc.NewServer()
grpcDone := make(chan error, 1) 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() { go func() {
a.logger.Info("gRPC server started", "addr", grpcAddr) a.logger.Info("gRPC server started", "addr", grpcAddr)
grpcDone <- grpcServer.Serve(lis) grpcDone <- grpcServer.Serve(lis)

View File

@ -1,4 +1,4 @@
package app package server
import ( import (
"testing" "testing"