From 03ad2420db9e8d639727799719867978233025d6 Mon Sep 17 00:00:00 2001 From: Adam Eijdenberg Date: Fri, 19 Jan 2024 12:09:13 +1100 Subject: [PATCH 1/2] fix: print the actual address listened on This is useful when the server is started with an ephemeral port, e.g.: ./rest-server --no-auth --listen "127.0.0.1:0" ... start server on 127.0.0.1:46015 --- changelog/unreleased/pull-271 | 17 +++++++++++++++++ cmd/rest-server/listener_unix.go | 2 +- cmd/rest-server/listener_windows.go | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/pull-271 diff --git a/changelog/unreleased/pull-271 b/changelog/unreleased/pull-271 new file mode 100644 index 00000000..ef2dc72a --- /dev/null +++ b/changelog/unreleased/pull-271 @@ -0,0 +1,17 @@ +Enhancement: after start-up, server served message now prints actual listen address + +For example, when started with `--listen :0`, previously the server would print: + +``` +start server on :0 +``` + +Now it will print the actual address listened on, e.g. + +``` +start server on 0.0.0.0:37333 +``` + +This is useful when starting a server with an auto-allocated free port number (port 0). + +https://github.com/restic/rest-server/pull/271 diff --git a/cmd/rest-server/listener_unix.go b/cmd/rest-server/listener_unix.go index 9e55d299..f3baf007 100644 --- a/cmd/rest-server/listener_unix.go +++ b/cmd/rest-server/listener_unix.go @@ -28,7 +28,7 @@ func findListener(addr string) (listener net.Listener, err error) { return nil, fmt.Errorf("listen on %v failed: %w", addr, err) } - log.Printf("start server on %v", addr) + log.Printf("start server on %v", listener.Addr()) return listener, nil case 1: diff --git a/cmd/rest-server/listener_windows.go b/cmd/rest-server/listener_windows.go index b1d8071d..cf74d6b9 100644 --- a/cmd/rest-server/listener_windows.go +++ b/cmd/rest-server/listener_windows.go @@ -14,6 +14,6 @@ func findListener(addr string) (listener net.Listener, err error) { return nil, fmt.Errorf("listen on %v failed: %w", addr, err) } - log.Printf("start server on %v", addr) + log.Printf("start server on %v", listener.Addr()) return listener, nil } From 4bfb2eaa81fa3c16aa3925a5b780ab500b3a385c Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Mon, 5 Feb 2024 20:50:09 +0100 Subject: [PATCH 2/2] simplify changelog for listen address --- changelog/unreleased/pull-271 | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/changelog/unreleased/pull-271 b/changelog/unreleased/pull-271 index ef2dc72a..f7855495 100644 --- a/changelog/unreleased/pull-271 +++ b/changelog/unreleased/pull-271 @@ -1,16 +1,9 @@ -Enhancement: after start-up, server served message now prints actual listen address +Enhancement: print actual listen address after start-up -For example, when started with `--listen :0`, previously the server would print: +When started with `--listen :0` the server would print `start server on :0` -``` -start server on :0 -``` - -Now it will print the actual address listened on, e.g. - -``` -start server on 0.0.0.0:37333 -``` +Now the message includes the actual address listened on, for example +`start server on 0.0.0.0:37333`. This is useful when starting a server with an auto-allocated free port number (port 0).