From b63c4e510c3e2a126dad0da4b433d1d4d15b10ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=96=84=E9=98=B3?= <864057710@qq.com> Date: Mon, 20 Jul 2020 09:58:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9adress.go=E7=9A=84convPort?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E6=94=AF=E6=8C=81IPv6=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E4=B9=8B=E9=97=B4=E5=BB=BA=E7=AB=8B=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E3=80=82=20(#248)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit monapi: http: '[::]:5800' address: - '[::1]' --- src/toolkits/address/address.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/toolkits/address/address.go b/src/toolkits/address/address.go index 96d62a60..cd427013 100644 --- a/src/toolkits/address/address.go +++ b/src/toolkits/address/address.go @@ -40,7 +40,11 @@ func GetRPCPort(mod string) int { } func convPort(module, listen, portType string) int { - port, err := strconv.Atoi(strings.Split(listen, ":")[1]) + splitChar := ":" + if IsIPv6(listen) { + splitChar = "]:" + } + port, err := strconv.Atoi(strings.Split(listen, splitChar)[1]) if err != nil { fmt.Printf("%s.%s invalid", module, portType) os.Exit(1) @@ -127,3 +131,8 @@ func getConf() string { os.Exit(1) return "" } + +func IsIPv6(address string) bool { + return strings.Count(address,":") >=2 +} +