Skip to content

Commit

Permalink
fix start method
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <[email protected]>
  • Loading branch information
nyagamunene committed Dec 11, 2024
1 parent 325f07a commit e9ace47
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,22 @@ func main() {
cfgM, err := config.LoadMQTTConfig(env.Options{Prefix: mqttPrefix})
if err != nil {
logger.Error("Failed to load MQTT configuration", slog.Any("error", err))
os.Exit(1)

return
}

cfgH, err := config.LoadHTTPConfig(env.Options{Prefix: httpPrefix})
if err != nil {
logger.Error("Failed to load HTTP configuration", slog.Any("error", err))
os.Exit(1)

return
}

service, err := proxy.NewService(ctx, cfgM, cfgH, logger)
if err != nil {
logger.Error("failed to create proxy service", "error", err)
os.Exit(1)

return
}

go func() {
Expand All @@ -70,7 +73,12 @@ func start(ctx context.Context, s *proxy.ProxyService) error {
if err := s.MQTTClient().Connect(ctx); err != nil {
return fmt.Errorf("failed to connect to MQTT broker: %w", err)
}
defer s.MQTTClient().Disconnect(ctx)

defer func() {
if err := s.MQTTClient().Disconnect(ctx); err != nil {
slog.Error("failed to disconnect MQTT client", "error", err)
}
}()

if err := s.MQTTClient().Subscribe(ctx, s.ContainerChan()); err != nil {
return fmt.Errorf("failed to subscribe to container requests: %w", err)
Expand Down

0 comments on commit e9ace47

Please sign in to comment.