Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/public/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"io"
"net"
"net/http"
"net/http/httputil"
"net/url"
Expand Down Expand Up @@ -1004,6 +1005,10 @@ func (s *Server) HealthCheck(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}

func listenAddr(host string, port int) string {
return net.JoinHostPort(host, strconv.Itoa(port))
}

func (s *Server) Serve(host string, port int) error {
log.Infof("Starting server at %s:%d", host, port)

Expand All @@ -1012,7 +1017,7 @@ func (s *Server) Serve(host string, port int) error {
s.wsHub.Run()

s.httpServer = &http.Server{
Addr: fmt.Sprintf("%s:%d", host, port),
Addr: listenAddr(host, port),
ReadTimeout: 5 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 60 * time.Second,
Expand Down
10 changes: 10 additions & 0 deletions pkg/public/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ func Test__HealthCheckEndpoint(t *testing.T) {
require.Equal(t, 200, response.Code)
}

func Test__ListenAddr(t *testing.T) {
t.Run("formats IPv4 addresses", func(t *testing.T) {
require.Equal(t, "127.0.0.1:3000", listenAddr("127.0.0.1", 3000))
})

t.Run("formats IPv6 addresses with brackets", func(t *testing.T) {
require.Equal(t, "[::1]:3000", listenAddr("::1", 3000))
})
}

func Test__OpenAPIEndpoints(t *testing.T) {
checkSwaggerFiles(t)

Expand Down