From 8bb17a44af9215b9d7cbf1347a42f32e84d26114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Bal=C3=A1=C5=BE?= Date: Sat, 27 Apr 2024 09:21:32 +0200 Subject: [PATCH] Simplify GetAddr --- internal/util.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/internal/util.go b/internal/util.go index ee96d73c4..235a91afa 100644 --- a/internal/util.go +++ b/internal/util.go @@ -67,20 +67,17 @@ func ReplaceSpaces(s string) string { } func GetAddr(addr string) string { - ind := strings.LastIndex(addr, ":") + ind := strings.LastIndexByte(addr, ':') if ind == -1 { return "" } - port := addr[ind+1:] - host := addr[:ind] - if string(host[0]) == "[" && string(host[len(host)-1]) == "]" { - host = host[1 : len(host)-1] + if strings.IndexByte(addr, '.') != -1 { + return addr } - if net.ParseIP(host) == nil { - return "" + if addr[0] == '[' { + return addr } - - return net.JoinHostPort(host, port) + return net.JoinHostPort(addr[:ind], addr[ind+1:]) }