detached 9ed3e41

refactor: extract resolveLogFilePath to reduce cyclomatic complexity

Extracts the log file path resolution logic into a separate helper
function to bring createServices below the complexity threshold.
commit
9ed3e413dcf90b09a38b662101c479387275791d
author
brice · · 2026-01-17 09:20 UTC
parent
25f0ae5
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
1 file · +12 -6
M internal/app/run.go +12 -6
@@ -322,12 +322,7 @@ func createServices(ctx context.Context, v *viper.Viper, cfg Config, log zerowra
322322 healthSvc := health.NewService(svc.configSvc, svc.containerSvc, prober, log)
323323
324324 // Create log service for accessing logs via admin API
325- logFilePath := cfg.Logging.File.Path
326- if logFilePath == "" && cfg.Logging.File.Enabled {
327- // Default to {data_dir}/logs/gordon.log when file logging enabled but no path specified
328- logFilePath = filepath.Join(cfg.Server.DataDir, "logs", "gordon.log")
329- }
330- logSvc := logs.NewService(logFilePath, svc.containerSvc, svc.runtime, log)
325+ logSvc := logs.NewService(resolveLogFilePath(cfg), svc.containerSvc, svc.runtime, log)
331326
332327 // Create admin handler for admin API
333328 svc.adminHandler = admin.NewHandler(svc.configSvc, svc.authSvc, svc.containerSvc, healthSvc, secretSvc, logSvc, svc.eventBus, log)
@@ -335,6 +330,17 @@ func createServices(ctx context.Context, v *viper.Viper, cfg Config, log zerowra
335330 return svc, nil
336331 }
337332
333+// resolveLogFilePath returns the configured log file path or a default.
334+func resolveLogFilePath(cfg Config) string {
335+ if cfg.Logging.File.Path != "" {
336+ return cfg.Logging.File.Path
337+ }
338+ if cfg.Logging.File.Enabled {
339+ return filepath.Join(cfg.Server.DataDir, "logs", "gordon.log")
340+ }
341+ return ""
342+}
343+
338344 // createOutputAdapters creates the Docker runtime and event bus.
339345 func createOutputAdapters(ctx context.Context, log zerowrap.Logger) (*docker.Runtime, *eventbus.InMemory, error) {
340346 runtime, err := docker.NewRuntime()
@@ -322,12 +322,7 @@ func createServices(ctx context.Context, v *viper.Viper, cfg Config, log zerowra
322 healthSvc := health.NewService(svc.configSvc, svc.containerSvc, prober, log)322 healthSvc := health.NewService(svc.configSvc, svc.containerSvc, prober, log)
323 323
324 // Create log service for accessing logs via admin API324 // Create log service for accessing logs via admin API
325- logFilePath := cfg.Logging.File.Path325+ logSvc := logs.NewService(resolveLogFilePath(cfg), svc.containerSvc, svc.runtime, log)
326- if logFilePath == "" && cfg.Logging.File.Enabled {
327- // Default to {data_dir}/logs/gordon.log when file logging enabled but no path specified
328- logFilePath = filepath.Join(cfg.Server.DataDir, "logs", "gordon.log")
329- }
330- logSvc := logs.NewService(logFilePath, svc.containerSvc, svc.runtime, log)
331 326
332 // Create admin handler for admin API327 // Create admin handler for admin API
333 svc.adminHandler = admin.NewHandler(svc.configSvc, svc.authSvc, svc.containerSvc, healthSvc, secretSvc, logSvc, svc.eventBus, log)328 svc.adminHandler = admin.NewHandler(svc.configSvc, svc.authSvc, svc.containerSvc, healthSvc, secretSvc, logSvc, svc.eventBus, log)
@@ -335,6 +330,17 @@ func createServices(ctx context.Context, v *viper.Viper, cfg Config, log zerowra
335 return svc, nil330 return svc, nil
336 }331 }
337 332
333+// resolveLogFilePath returns the configured log file path or a default.
334+func resolveLogFilePath(cfg Config) string {
335+ if cfg.Logging.File.Path != "" {
336+ return cfg.Logging.File.Path
337+ }
338+ if cfg.Logging.File.Enabled {
339+ return filepath.Join(cfg.Server.DataDir, "logs", "gordon.log")
340+ }
341+ return ""
342+}
343+
338 // createOutputAdapters creates the Docker runtime and event bus.344 // createOutputAdapters creates the Docker runtime and event bus.
339 func createOutputAdapters(ctx context.Context, log zerowrap.Logger) (*docker.Runtime, *eventbus.InMemory, error) {345 func createOutputAdapters(ctx context.Context, log zerowrap.Logger) (*docker.Runtime, *eventbus.InMemory, error) {
340 runtime, err := docker.NewRuntime()346 runtime, err := docker.NewRuntime()

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close