Alanxtl commented on code in PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#discussion_r3401407882


##########
common/url.go:
##########
@@ -839,24 +864,18 @@ func (c *URL) ToMap() map[string]string {
                paramsMap["password"] = c.Password
        }
        if c.Location != "" {
-               paramsMap["host"] = strings.Split(c.Location, ":")[0]
-               var port string
-               if strings.Contains(c.Location, ":") {
-                       port = strings.Split(c.Location, ":")[1]
+               // Single-pass split avoids repeated string scanning.
+               parts := strings.Split(c.Location, ":")
+               paramsMap["host"] = parts[0]
+               if len(parts) > 1 {
+                       paramsMap["port"] = parts[len(parts)-1]
                } else {
-                       port = "0"
+                       paramsMap["port"] = "0"
                }

Review Comment:
   `ToMap` 的多地址 port 解析语义被改了
   
      原逻辑对 `127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183` 的 `port` 是 
`2181,127.0.0.1` 确实不合理,
      PR 改成取最后一个 `:` 后的 `2183`。也不合理
   
     这里改成合理的逻辑,然后在pr简介里面说明



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to