Refactor application initialization to load configuration and enhance message processing. Introduce effective subscription topic handling and improve error management in NATS consumer. Update tests for publisher error handling and add new dependency injection method for app initialization.

This commit is contained in:
windyboy
2025-11-14 22:43:04 +08:00
parent 9cce4610b6
commit 02e54a2670
8 changed files with 196 additions and 35 deletions
+15 -1
View File
@@ -1,6 +1,7 @@
package main
import (
"caatsm/internal/infra/config"
"caatsm/pkg/di"
"context"
"errors"
@@ -52,8 +53,21 @@ func setupApp() *cli.App {
}
func executeListen(c *cli.Context) error {
cfg, err := config.LoadConfig()
if err != nil {
return fmt.Errorf("failed to load config: %w", err)
}
if flagURL := c.String("nats"); flagURL != "" {
cfg.NATS.URL = flagURL
}
if flagTopic := c.String("topic"); flagTopic != "" {
cfg.Subscription.Topic = flagTopic
}
// Initialize dependencies using Wire
processor, consumer, err := di.InitializeApp()
processor, consumer, err := di.InitializeAppWithConfig(cfg)
if err != nil {
return fmt.Errorf("failed to initialize app: %w", err)
}