fixup! wip: refactor: API

This commit is contained in:
Rob Watson 2025-05-11 07:55:06 +02:00
parent d0d96dd1d9
commit c5724dfe59
3 changed files with 36 additions and 51 deletions

View File

@ -10,7 +10,7 @@ import (
"os"
"os/exec"
"os/signal"
"runtime/debug"
"runtime"
"syscall"
"git.netflux.io/rob/octoplex/internal/app"
@ -88,7 +88,6 @@ func run() error {
return fmt.Errorf("build logger: %w", err)
}
// When running in headless mode tview doesn't handle SIGINT for us.
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
@ -107,24 +106,25 @@ func run() error {
return fmt.Errorf("new docker client: %w", err)
}
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return fmt.Errorf("read build info: %w", err)
}
app := app.New(app.Params{
ConfigService: configService,
DockerClient: dockerClient,
ConfigFilePath: configService.Path(),
BuildInfo: domain.BuildInfo{
GoVersion: buildInfo.GoVersion,
Version: version,
Commit: commit,
Date: date,
},
Logger: logger,
})
logger.Info(
"Starting application",
"version",
cmp.Or(version, "devel"),
"commit",
cmp.Or(commit, "unknown"),
"date",
cmp.Or(date, "unknown"),
"go_version",
runtime.Version(),
)
if err := app.Run(ctx); err != nil {
if errors.Is(err, context.Canceled) && context.Cause(ctx) == errShutdown {
return errShutdown

View File

@ -19,7 +19,6 @@ import (
"git.netflux.io/rob/octoplex/internal/mediaserver"
"git.netflux.io/rob/octoplex/internal/replicator"
"git.netflux.io/rob/octoplex/internal/server"
"git.netflux.io/rob/octoplex/internal/terminal"
"github.com/docker/docker/client"
"google.golang.org/grpc"
)
@ -31,10 +30,6 @@ type App struct {
eventBus *event.Bus
dispatchC chan event.Command
dockerClient container.DockerClient
screen *terminal.Screen // Screen may be nil.
clipboardAvailable bool
configFilePath string
buildInfo domain.BuildInfo
logger *slog.Logger
}
@ -43,9 +38,7 @@ type Params struct {
ConfigService *config.Service
DockerClient container.DockerClient
ChanSize int
ClipboardAvailable bool
ConfigFilePath string
BuildInfo domain.BuildInfo
Logger *slog.Logger
}
@ -60,9 +53,6 @@ func New(params Params) *App {
eventBus: event.NewBus(params.Logger.With("component", "event_bus")),
dispatchC: make(chan event.Command, cmp.Or(params.ChanSize, defaultChanSize)),
dockerClient: params.DockerClient,
clipboardAvailable: params.ClipboardAvailable,
configFilePath: params.ConfigFilePath,
buildInfo: params.BuildInfo,
logger: params.Logger,
}
}
@ -78,8 +68,7 @@ func (a *App) Run(ctx context.Context) error {
return errors.New("config: either sources.mediaServer.rtmp.enabled or sources.mediaServer.rtmps.enabled must be set")
}
// doFatalError publishes a fatal error to the event bus, waiting for the
// user to acknowledge it if not in headless mode.
// doFatalError publishes a fatal error to the event bus.
doFatalError := func(msg string) {
a.eventBus.Send(event.FatalErrorOccurredEvent{Message: msg})
}

View File

@ -33,10 +33,8 @@ func buildClientServer(
screenCaptureC chan<- terminal.ScreenCapture,
logger *slog.Logger,
) (*client.App, *app.App) {
buildInfo := domain.BuildInfo{Version: "0.0.1", GoVersion: "go1.16.3"}
client := client.New(client.NewParams{
BuildInfo: buildInfo,
BuildInfo: domain.BuildInfo{Version: "0.0.1", GoVersion: "go1.16.3"},
Screen: &terminal.Screen{
Screen: screen,
Width: 160,
@ -49,8 +47,6 @@ func buildClientServer(
server := app.New(app.Params{
ConfigService: configService,
DockerClient: dockerClient,
ClipboardAvailable: false,
BuildInfo: buildInfo,
Logger: logger,
})