From a86192e1b277f84eebbad7f9b1f7247986645415 Mon Sep 17 00:00:00 2001 From: D3Hunter Date: Wed, 13 Jul 2022 16:54:13 +0800 Subject: [PATCH] use net.JoinHostPort --- cmd/go-canal/main.go | 4 +++- replication/binlogsyncer.go | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/go-canal/main.go b/cmd/go-canal/main.go index 9f7d59226..8e8267327 100644 --- a/cmd/go-canal/main.go +++ b/cmd/go-canal/main.go @@ -3,8 +3,10 @@ package main import ( "flag" "fmt" + "net" "os" "os/signal" + "strconv" "strings" "syscall" "time" @@ -38,7 +40,7 @@ func main() { flag.Parse() cfg := canal.NewDefaultConfig() - cfg.Addr = fmt.Sprintf("%s:%d", *host, *port) + cfg.Addr = net.JoinHostPort(*host, strconv.Itoa(*port)) cfg.User = *user cfg.Password = *password cfg.Flavor = *flavor diff --git a/replication/binlogsyncer.go b/replication/binlogsyncer.go index 196eb0870..8a8c2fd22 100644 --- a/replication/binlogsyncer.go +++ b/replication/binlogsyncer.go @@ -7,6 +7,7 @@ import ( "fmt" "net" "os" + "strconv" "sync" "time" @@ -866,7 +867,7 @@ func (b *BinlogSyncer) LastConnectionID() uint32 { func (b *BinlogSyncer) newConnection() (*client.Conn, error) { var addr string if b.cfg.Port != 0 { - addr = fmt.Sprintf("%s:%d", b.cfg.Host, b.cfg.Port) + addr = net.JoinHostPort(b.cfg.Host, strconv.Itoa(int(b.cfg.Port))) } else { addr = b.cfg.Host }