From 59dc892ce65bfb0117bbec32f6e84c1f95b696fd Mon Sep 17 00:00:00 2001 From: Will Owens Date: Sun, 15 Mar 2026 15:06:58 -0500 Subject: [PATCH] logging: output infinite max connections as infinity symbol --- server/handlers.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/server/handlers.go b/server/handlers.go index 4f3f8fc..d22afd9 100644 --- a/server/handlers.go +++ b/server/handlers.go @@ -16,6 +16,13 @@ import ( "github.com/ghthor/gotty/v2/webtty" ) +func zeroAsInfinity(format string, v int) string { + if v == 0 { + return "∞" + } + return fmt.Sprintf(format, v) +} + func (server *Server) generateHandleWS(ctx context.Context, cancel context.CancelFunc, counter *counter) http.HandlerFunc { once := new(int64) @@ -42,8 +49,8 @@ func (server *Server) generateHandleWS(ctx context.Context, cancel context.Cance defer func() { num := counter.done() log.Printf( - "Connection closed by %s: %s, connections: %d/%d", - closeReason, r.RemoteAddr, num, server.options.MaxConnection, + "Connection closed by %s: %s, connections: %d/%s", + closeReason, r.RemoteAddr, num, zeroAsInfinity("%d", server.options.MaxConnection), ) if server.options.Once { @@ -58,7 +65,10 @@ func (server *Server) generateHandleWS(ctx context.Context, cancel context.Cance } } - log.Printf("New client connected: %s, connections: %d/%d", r.RemoteAddr, num, server.options.MaxConnection) + log.Printf( + "New client connected: %s, connections: %d/%s", + r.RemoteAddr, num, zeroAsInfinity("%d", server.options.MaxConnection), + ) if r.Method != "GET" { http.Error(w, "Method not allowed", 405)