diff options
author | greatroar <61184462+greatroar@users.noreply.github.com> | 2023-12-20 11:59:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-20 11:59:11 +0100 |
commit | cdefa535edc6a3901d3b774911d90fd93cebed28 (patch) | |
tree | 5a88b546d67f471afa2fcd4a07a83b1b4544fd06 | |
parent | 91084b83b4964dfe1b4ce8830aabeb49ec9254f4 (diff) | |
download | syncthing-cdefa535edc6a3901d3b774911d90fd93cebed28.tar.gz syncthing-cdefa535edc6a3901d3b774911d90fd93cebed28.zip |
lib/connections: Skip allocation in check for missing port (#9297)
Micro-optimization. Already has unit tests.
-rw-r--r-- | lib/connections/util.go | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/connections/util.go b/lib/connections/util.go index 7f6c3fd60..217d006f4 100644 --- a/lib/connections/util.go +++ b/lib/connections/util.go @@ -19,8 +19,8 @@ func fixupPort(uri *url.URL, defaultPort int) *url.URL { copyURI := *uri host, port, err := net.SplitHostPort(uri.Host) - if err != nil && strings.Contains(err.Error(), "missing port") { - // addr is on the form "1.2.3.4" or "[fe80::1]" + if e, ok := err.(*net.AddrError); ok && strings.Contains(e.Err, "missing port") { + // addr is of the form "1.2.3.4" or "[fe80::1]" host = uri.Host if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") { // net.JoinHostPort will add the brackets again |