From 51f9953e6e4d50fdaf76071525c48ed467cbc7fc Mon Sep 17 00:00:00 2001 From: amirhnajafiz Date: Wed, 23 Aug 2023 09:25:40 +0330 Subject: [PATCH] update: server mux --- internal/server.go | 6 ++++-- test/server_test.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/server.go b/internal/server.go index cb0f503..5fdfdc5 100644 --- a/internal/server.go +++ b/internal/server.go @@ -93,11 +93,13 @@ func (s *server) metricsHandler(w http.ResponseWriter, _ *http.Request) { // serveMetrics http server func (s *server) serveMetrics(port int) { - http.HandleFunc("/metrics", s.metricsHandler) + mux := http.NewServeMux() + + mux.HandleFunc("/metrics", s.metricsHandler) log.Println(fmt.Sprintf("metrics server started on %d ...", port)) - if err := http.ListenAndServe(fmt.Sprintf(":%d", port), nil); err != nil { + if err := http.ListenAndServe(fmt.Sprintf(":%d", port), mux); err != nil { log.Println(fmt.Errorf("failed to start metrics server error=%w", err)) } } diff --git a/test/server_test.go b/test/server_test.go index 7e2bfcb..a442174 100644 --- a/test/server_test.go +++ b/test/server_test.go @@ -44,7 +44,7 @@ func TestServer(t *testing.T) { // TestAuthServer // testing stallion server with auth. func TestAuthServer(t *testing.T) { - // creating a stallion server on port 6001 with user and pass + // creating a stallion server on port 6002 with user and pass go func() { if err := stallion.NewServer(":6002", 6003, "root", "password"); err != nil { t.Errorf("server failed to start: %v", err)