mirror of
https://github.com/onyx-and-iris/q3rcon-proxy.git
synced 2026-02-20 02:29:12 +00:00
use net.JoinHostPort to build addresses
This commit is contained in:
parent
63cf99b217
commit
225188bb70
@ -4,6 +4,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -158,18 +159,18 @@ func main() {
|
|||||||
func launchProxy(cfg proxyConfig, errChan chan<- error) {
|
func launchProxy(cfg proxyConfig, errChan chan<- error) {
|
||||||
proxyPort, targetPort := cfg.portsMapping[0], cfg.portsMapping[1]
|
proxyPort, targetPort := cfg.portsMapping[0], cfg.portsMapping[1]
|
||||||
|
|
||||||
hostAddr := fmt.Sprintf("%s:%s", cfg.proxyHost, proxyPort)
|
proxyAddr := net.JoinHostPort(cfg.proxyHost, proxyPort)
|
||||||
proxyAddr := fmt.Sprintf("%s:%s", cfg.targetHost, targetPort)
|
targetAddr := net.JoinHostPort(cfg.targetHost, targetPort)
|
||||||
|
|
||||||
server, err := udpproxy.New(
|
server, err := udpproxy.New(
|
||||||
hostAddr, proxyAddr,
|
proxyAddr, targetAddr,
|
||||||
udpproxy.WithSessionTimeout(time.Duration(cfg.sessionTimeout)*time.Minute))
|
udpproxy.WithSessionTimeout(time.Duration(cfg.sessionTimeout)*time.Minute))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errChan <- fmt.Errorf("failed to create proxy: %w", err)
|
errChan <- fmt.Errorf("failed to create proxy: %w", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("q3rcon-proxy initialised: [proxy] (%s) [target] (%s)", hostAddr, proxyAddr)
|
log.Infof("q3rcon-proxy initialised: [proxy] (%s) [target] (%s)", proxyAddr, targetAddr)
|
||||||
|
|
||||||
errChan <- server.ListenAndServe()
|
errChan <- server.ListenAndServe()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user