Explorar el Código

lib/connections: Skip allocation in check for missing port (#9297)

Micro-optimization. Already has unit tests.
greatroar hace 2 años
padre
commit
cdefa535ed
Se han modificado 1 ficheros con 2 adiciones y 2 borrados
  1. 2 2
      lib/connections/util.go

+ 2 - 2
lib/connections/util.go

@@ -19,8 +19,8 @@ func fixupPort(uri *url.URL, defaultPort int) *url.URL {
 	copyURI := *uri
 	copyURI := *uri
 
 
 	host, port, err := net.SplitHostPort(uri.Host)
 	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
 		host = uri.Host
 		if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") {
 		if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") {
 			// net.JoinHostPort will add the brackets again
 			// net.JoinHostPort will add the brackets again