Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Dec 10, 2024
1 parent 9db84ba commit b69e5cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
13 changes: 4 additions & 9 deletions server/v2/api/rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ func New[T transaction.Tx](
}
}
srv.config = serverCfg
srv.init()
srv.httpServer = &http.Server{
Addr: srv.config.Address,
Handler: srv.router,
}
return srv, nil
}

Expand All @@ -59,13 +62,6 @@ func NewWithConfigOptions[T transaction.Tx](opts ...CfgOption) *Server[T] {
}
}

func (s *Server[T]) init() {
s.httpServer = &http.Server{
Addr: s.config.Address,
Handler: s.router,
}
}

func (s *Server[T]) Name() string {
return ServerName
}
Expand All @@ -91,7 +87,6 @@ func (s *Server[T]) Stop(ctx context.Context) error {
}

s.logger.Info("stopping HTTP server")
defer s.init()
return s.httpServer.Shutdown(ctx)
}

Expand Down
13 changes: 4 additions & 9 deletions server/v2/api/telemetry/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,18 @@ func New[T transaction.Tx](cfg server.ConfigMap, logger log.Logger, enableTeleme
return nil, fmt.Errorf("failed to initialize metrics: %w", err)
}
srv.metrics = metrics
srv.init()
return srv, nil
}

func (s *Server[T]) init() {
mux := http.NewServeMux()
// /metrics is the default standard path for Prometheus metrics.
mux.HandleFunc("/metrics", s.metricsHandler)
mux.HandleFunc("/metrics", srv.metricsHandler)
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/metrics", http.StatusMovedPermanently)
})

s.server = &http.Server{
Addr: s.config.Address,
srv.server = &http.Server{
Addr: srv.config.Address,
Handler: mux,
}
return srv, nil
}

// Name returns the server name.
Expand Down Expand Up @@ -102,7 +98,6 @@ func (s *Server[T]) Stop(ctx context.Context) error {
return nil
}

defer s.init()
s.logger.Info("stopping telemetry server...", "address", s.config.Address)
return s.server.Shutdown(ctx)
}
Expand Down

0 comments on commit b69e5cd

Please sign in to comment.