From c9d174c6d4216a334b0dc190a4f70faa49028e4b Mon Sep 17 00:00:00 2001 From: Nya Candy Date: Mon, 25 Mar 2024 16:41:22 +0800 Subject: [PATCH] chore: tweak initialize process --- internal/service/gateway/server.go | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/internal/service/gateway/server.go b/internal/service/gateway/server.go index da87167..4086bc9 100644 --- a/internal/service/gateway/server.go +++ b/internal/service/gateway/server.go @@ -39,18 +39,6 @@ func (s *Server) Run(ctx context.Context) error { // Run echo server. errorPool.Go(func(ctx context.Context) error { - // Prepare JWT - jwtClient, err := jwt.New(s.config.API.JWTKey) - if err != nil { - return fmt.Errorf("prepare JWT: %w", err) - } - - // Prepare SIWE - siweClient, err := siwe.New(s.config.API.SIWEDomain, s.redis) - if err != nil { - return fmt.Errorf("prepare SIWE: %w", err) - } - // Connect to kafka for access logs kafkaClient, err := accesslog.NewConsumer( s.config.Kafka.Brokers, @@ -62,14 +50,24 @@ func (s *Server) Run(ctx context.Context) error { } // Prepare processors - processorApp, err := processors.NewApp(s.controlClient, s.databaseClient.Raw()) - if err != nil { + if processorApp, err := processors.NewApp(s.controlClient, s.databaseClient.Raw()); err != nil { return fmt.Errorf("prepare processors: %w", err) + } else if err = kafkaClient.Start(processorApp.ProcessAccessLog); err != nil { + return fmt.Errorf("start kafka client: %w", err) } - err = kafkaClient.Start(processorApp.ProcessAccessLog) + zap.L().Debug("processors started") + + // Prepare JWT + jwtClient, err := jwt.New(s.config.API.JWTKey) if err != nil { - return fmt.Errorf("start kafka: %w", err) + return fmt.Errorf("prepare JWT: %w", err) + } + + // Prepare SIWE + siweClient, err := siwe.New(s.config.API.SIWEDomain, s.redis) + if err != nil { + return fmt.Errorf("prepare SIWE: %w", err) } // Prepare handler