From 23e8f7e0aac12825ecd74ce4ce08b76a743a82b7 Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Sun, 28 Jul 2024 05:34:49 +0300 Subject: [PATCH] refactor(api): move port extraction logic to Init function for prevent data race --- internal/api/api.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/internal/api/api.go b/internal/api/api.go index 86817bd0..419e2bdf 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -69,6 +69,8 @@ func Init() { } if cfg.Mod.Listen != "" { + _, port, _ := net.SplitHostPort(cfg.Mod.Listen) + Port, _ = strconv.Atoi(port) go listen("tcp", cfg.Mod.Listen) } @@ -92,10 +94,6 @@ func listen(network, address string) { log.Info().Str("addr", address).Msg("[api] listen") - if network == "tcp" { - Port = ln.Addr().(*net.TCPAddr).Port - } - server := http.Server{ Handler: Handler, ReadHeaderTimeout: 5 * time.Second, // Example: Set to 5 seconds