From 6489d1e556b1294d3107abfe35abb8216ab51ceb Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Mon, 12 May 2025 00:01:00 +0100 Subject: [PATCH] return value straight from errChan --- cmd/q3rcon-proxy/main.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/cmd/q3rcon-proxy/main.go b/cmd/q3rcon-proxy/main.go index 6c4fd41..b2bdfb6 100644 --- a/cmd/q3rcon-proxy/main.go +++ b/cmd/q3rcon-proxy/main.go @@ -34,7 +34,7 @@ func main() { }, &cli.StringFlag{ Name: "target-host", - Value: "127.0.0.1", + Value: "localhost", Usage: "Target host address", Sources: cli.EnvVars("Q3RCON_TARGET_HOST"), }, @@ -100,26 +100,19 @@ func main() { go launchProxy(cfg, errChan) } - // Under normal circumstances, the main goroutine will block here - // until the server is stopped or an error occurs. - for err := range errChan { - if err != nil { - return err - } - } - return nil + // Under normal circumstances, the main goroutine will block here. + // If we receive an error we will log it and exit + return <-errChan }, } - if err := cmd.Run(context.Background(), os.Args); err != nil { - log.Fatal(err) - } + log.Fatal(cmd.Run(context.Background(), os.Args)) } // launchProxy initializes the UDP proxy server with the given configuration. // It listens on the specified proxy host and port, and forwards traffic to the target host and port. // server.ListenAndServe blocks until the server is stopped or an error occurs. -func launchProxy(cfg proxyConfig, errChan chan error) { +func launchProxy(cfg proxyConfig, errChan chan<- error) { proxyPort, targetPort := cfg.portsMapping[0], cfg.portsMapping[1] hostAddr := fmt.Sprintf("%s:%s", cfg.proxyHost, proxyPort)