rename initProxy to launchProxy

remove double log on error

add some explanatory comments.
This commit is contained in:
onyx-and-iris 2025-05-07 16:16:35 +01:00
parent a00796254d
commit d0e3f5863a

View File

@ -13,6 +13,7 @@ import (
"github.com/urfave/cli/v3"
)
// proxyConfig holds the configuration for a single UDP proxy server.
type proxyConfig struct {
proxyHost string
targetHost string
@ -96,13 +97,13 @@ func main() {
sessionTimeout: cmd.Int("session-timeout"),
}
go initProxy(cfg, errChan)
go launchProxy(cfg, errChan)
}
// We don't expect to receive any errors from the channels, but if we do, we log and return early.
// 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 {
log.Errorf("Error: %v", err)
return err
}
}
@ -115,7 +116,10 @@ func main() {
}
}
func initProxy(cfg proxyConfig, errChan chan error) {
// 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) {
proxyPort, targetPort := cfg.portsMapping[0], cfg.portsMapping[1]
hostAddr := fmt.Sprintf("%s:%s", cfg.proxyHost, proxyPort)