Skip to content

Commit 95942b0

Browse files
committed
feat(dumper): use net.SplitHostPort to parse address
1 parent 5459d61 commit 95942b0

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

dump/dumper.go

Lines changed: 4 additions & 14 deletions
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"
@@ -212,20 +213,9 @@ func (d *Dumper) Dump(w io.Writer) error {
212213
if strings.Contains(d.Addr, "/") {
213214
args = append(args, fmt.Sprintf("--socket=%s", d.Addr))
214215
} else {
215-
ipv6 := strings.Count(d.Addr, ":") > 1
216-
lastSep := strings.LastIndex(d.Addr, ":")
217-
var host, port string
218-
// without port
219-
host = d.Addr
220-
// ipv6 with port
221-
if ipv6 && strings.ContainsAny(d.Addr, "[]") {
222-
host = strings.Trim(d.Addr[:lastSep], "[]")
223-
port = d.Addr[lastSep+1:]
224-
}
225-
// ipv4 with port
226-
if !ipv6 && lastSep != -1 {
227-
host = d.Addr[:lastSep]
228-
port = d.Addr[lastSep+1:]
216+
host, port, err := net.SplitHostPort(d.Addr)
217+
if err != nil {
218+
host = d.Addr
229219
}
230220

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

0 commit comments

Comments
 (0)