Skip to content

Commit 4222b9c

Browse files
committed
feat(dumper): use net.SplitHostPort to parse address
1 parent 7c5a140 commit 4222b9c

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

dump/dumper.go

+4-14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"fmt"
66
"io"
7+
"net"
78
"os"
89
"os/exec"
910
"regexp"
@@ -202,20 +203,9 @@ func (d *Dumper) Dump(w io.Writer) error {
202203
if strings.Contains(d.Addr, "/") {
203204
args = append(args, fmt.Sprintf("--socket=%s", d.Addr))
204205
} else {
205-
ipv6 := strings.Count(d.Addr, ":") > 1
206-
lastSep := strings.LastIndex(d.Addr, ":")
207-
var host, port string
208-
// without port
209-
host = d.Addr
210-
// ipv6 with port
211-
if ipv6 && strings.ContainsAny(d.Addr, "[]") {
212-
host = strings.Trim(d.Addr[:lastSep], "[]")
213-
port = d.Addr[lastSep+1:]
214-
}
215-
// ipv4 with port
216-
if !ipv6 && lastSep != -1 {
217-
host = d.Addr[:lastSep]
218-
port = d.Addr[lastSep+1:]
206+
host, port, err := net.SplitHostPort(d.Addr)
207+
if err != nil {
208+
host = d.Addr
219209
}
220210

221211
args = append(args, fmt.Sprintf("--host=%s", host))

0 commit comments

Comments
 (0)