WIP: refactor/api #1
@ -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: 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
|
||||
|
@ -19,34 +19,27 @@ 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"
|
||||
)
|
||||
|
||||
// App is an instance of the app.
|
||||
type App struct {
|
||||
cfg config.Config
|
||||
configService *config.Service
|
||||
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
|
||||
cfg config.Config
|
||||
configService *config.Service
|
||||
eventBus *event.Bus
|
||||
dispatchC chan event.Command
|
||||
dockerClient container.DockerClient
|
||||
logger *slog.Logger
|
||||
}
|
||||
|
||||
// Params holds the parameters for running the application.
|
||||
type Params struct {
|
||||
ConfigService *config.Service
|
||||
DockerClient container.DockerClient
|
||||
ChanSize int
|
||||
ClipboardAvailable bool
|
||||
ConfigFilePath string
|
||||
BuildInfo domain.BuildInfo
|
||||
Logger *slog.Logger
|
||||
ConfigService *config.Service
|
||||
DockerClient container.DockerClient
|
||||
ChanSize int
|
||||
ConfigFilePath string
|
||||
Logger *slog.Logger
|
||||
}
|
||||
|
||||
// defaultChanSize is the default size of the dispatch channel.
|
||||
@ -55,15 +48,12 @@ const defaultChanSize = 64
|
||||
// New creates a new application instance.
|
||||
func New(params Params) *App {
|
||||
return &App{
|
||||
cfg: params.ConfigService.Current(),
|
||||
configService: params.ConfigService,
|
||||
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,
|
||||
cfg: params.ConfigService.Current(),
|
||||
configService: params.ConfigService,
|
||||
eventBus: event.NewBus(params.Logger.With("component", "event_bus")),
|
||||
dispatchC: make(chan event.Command, cmp.Or(params.ChanSize, defaultChanSize)),
|
||||
dockerClient: params.DockerClient,
|
||||
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})
|
||||
}
|
||||
|
@ -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,
|
||||
@ -47,11 +45,9 @@ func buildClientServer(
|
||||
})
|
||||
|
||||
server := app.New(app.Params{
|
||||
ConfigService: configService,
|
||||
DockerClient: dockerClient,
|
||||
ClipboardAvailable: false,
|
||||
BuildInfo: buildInfo,
|
||||
Logger: logger,
|
||||
ConfigService: configService,
|
||||
DockerClient: dockerClient,
|
||||
Logger: logger,
|
||||
})
|
||||
|
||||
return client, server
|
||||
|
Loading…
x
Reference in New Issue
Block a user