Skip to content

Commit e28aed3

Browse files
authored
Merge pull request go-mysql-org#715 from D3Hunter/join-addr
use net.JoinHostPort to join host and port
2 parents 6e0ddbf + a86192e commit e28aed3

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

cmd/go-canal/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package main
33
import (
44
"flag"
55
"fmt"
6+
"net"
67
"os"
78
"os/signal"
9+
"strconv"
810
"strings"
911
"syscall"
1012
"time"
@@ -38,7 +40,7 @@ func main() {
3840
flag.Parse()
3941

4042
cfg := canal.NewDefaultConfig()
41-
cfg.Addr = fmt.Sprintf("%s:%d", *host, *port)
43+
cfg.Addr = net.JoinHostPort(*host, strconv.Itoa(*port))
4244
cfg.User = *user
4345
cfg.Password = *password
4446
cfg.Flavor = *flavor

replication/binlogsyncer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"net"
99
"os"
10+
"strconv"
1011
"sync"
1112
"time"
1213

@@ -866,7 +867,7 @@ func (b *BinlogSyncer) LastConnectionID() uint32 {
866867
func (b *BinlogSyncer) newConnection() (*client.Conn, error) {
867868
var addr string
868869
if b.cfg.Port != 0 {
869-
addr = fmt.Sprintf("%s:%d", b.cfg.Host, b.cfg.Port)
870+
addr = net.JoinHostPort(b.cfg.Host, strconv.Itoa(int(b.cfg.Port)))
870871
} else {
871872
addr = b.cfg.Host
872873
}

0 commit comments

Comments
 (0)