restic / rest-server

Rest Server is a high performance HTTP server that implements restic's REST backend API.
BSD 2-Clause "Simplified" License
899 stars 139 forks source link

fix: print the actual address listened on #271

Closed ae-govau closed 5 months ago

ae-govau commented 6 months ago

What is the purpose of this change? What does it change?

When used in scripts it can be useful to start a server with an ephemeral port number (e.g. a free port selected automatically by the application).

rest-server already does this (it's handled by net.Listen()), but the current code doesn't print the selected port - rather it prints the requested port (0).

This changes the behaviour to print the address returned by net.Listen.

This is useful when the server is started with an ephemeral port, e.g. previously running:

./rest-server --no-auth --listen "127.0.0.1:0"

would print:

start server on 127.0.0.1:0

With this change the output now shows the actual port selected, e.g.

start server on 127.0.0.1:46015

Was the change discussed in an issue or in the forum before?

No. For such a simple change, I thought it would less effort to go straight to a PR. Happy to make changes if needed.

Checklist

ae-govau commented 5 months ago

Rebased, added changelog, tweaked output format.