Skip to content

Commit

Permalink
update: server mux
Browse files Browse the repository at this point in the history
  • Loading branch information
amirhnajafiz committed Aug 23, 2023
1 parent 408fbf6 commit 51f9953
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions internal/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
2 changes: 1 addition & 1 deletion test/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 51f9953

Please sign in to comment.