Skip to content

Commit 97d3ac3

Browse files
committed
fix: refactor main.go
1 parent 1bc49e8 commit 97d3ac3

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ out/
3737

3838
# Database files
3939
agent-browser.db-journal
40+
agent-browser

cmd/agent-browser/main.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,35 @@ import (
99
"go.uber.org/fx/fxevent"
1010
)
1111

12-
func main() {
13-
// Create the fx application using the core modules.
14-
// Lifecycle management is handled within the invoked functions in the modules.
15-
fxApp := fx.New(
12+
// --- Logger Configuration ---
13+
14+
// provideFxLogger creates a custom fxevent.Logger adapter using our application logger.
15+
// This ensures fx framework logs are routed through our structured logging system.
16+
func provideFxLogger(logger log.Logger) fxevent.Logger {
17+
return log.NewFxZerologAdapter(logger)
18+
}
19+
20+
// --- Application Setup ---
21+
22+
// buildApplication constructs the fx application with all required modules and configuration.
23+
func buildApplication() *fx.App {
24+
return fx.New(
25+
// Core application modules
1626
app.CoreModules,
1727

18-
// Configure Fx to use our custom log.Logger via the adapter
19-
fx.WithLogger(func(logger log.Logger) fxevent.Logger {
20-
// Use the adapter we created
21-
return log.NewFxZerologAdapter(logger)
22-
}),
28+
// Configure Fx to use our custom logger
29+
fx.WithLogger(provideFxLogger),
2330
)
31+
}
32+
33+
// --- Main Entry Point ---
34+
35+
// main is the application entry point that builds and runs the application.
36+
func main() {
37+
// Build the application with all modules and configuration
38+
fxApp := buildApplication()
2439

25-
// Run the application.
26-
// This blocks until the application stops.
40+
// Run the application (blocks until application stops)
2741
fxApp.Run()
2842

2943
// fxApp.Err() could be checked here if needed

0 commit comments

Comments
 (0)