Add --port

This commit is contained in:
2026-09-12 23:48:03 +02:00
parent a180fe4b52
commit da36645aaf
14 changed files with 677 additions and 40 deletions
+10 -2
View File
@@ -8,6 +8,7 @@ import (
"flag"
"fmt"
"log/slog"
"net"
"net/http"
"os"
"os/signal"
@@ -99,6 +100,13 @@ func serve(args []string) error {
ErrorLog: slog.NewLogLogger(log.Handler(), slog.LevelWarn),
}
// Bind before announcing anything: logging "listening" and only then
// failing to bind reads as a server that started and then died.
ln, err := net.Listen("tcp", cfg.Listen)
if err != nil {
return err
}
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
@@ -106,14 +114,14 @@ func serve(args []string) error {
go reloadOnHUP(ctx, tokens, log)
log.Info("listening",
"addr", cfg.Listen, "data", cfg.DataDir, "base", cfg.BasePath,
"addr", ln.Addr().String(), "data", cfg.DataDir, "base", cfg.BasePath,
"objects", st.Count(), "stored", config.FormatBytes(st.Total()),
"max_size", config.FormatSize(cfg.MaxSize),
"max_expiry", config.FormatDuration(cfg.MaxExpiry))
errc := make(chan error, 1)
go func() {
err := httpSrv.ListenAndServe()
err := httpSrv.Serve(ln)
if errors.Is(err, http.ErrServerClosed) {
err = nil
}