AlexStocks commented on code in PR #3331:
URL: https://github.com/apache/dubbo-go/pull/3331#discussion_r3308067426
##########
config_center/apollo/impl.go:
##########
@@ -222,10 +222,14 @@ func (c *apolloConfiguration)
getAddressWithProtocolPrefix(url *common.URL) stri
addr := regexp.MustCompile(`\s+`).ReplaceAllString(address, "")
parts := strings.Split(addr, ",")
addrs := make([]string, 0)
+ path := strings.Trim(url.Path, "/")
for _, part := range parts {
addr := part
+ if path != "" {
+ addr = strings.TrimRight(addr, "/") + "/" + path
Review Comment:
[P1] 多地址场景下 `url.Path` 的归属有歧义。
当配置为 `apollo://127.0.0.1:8080,192.168.1.1:8080/config` 时,Go 的 `net/url` 会把
`/config` 解析到 `url.Path`,但 `127.0.0.1:8080` 作为 `url.Host` 只有第一个地址。当前逻辑会把 path
统一拼到**所有**逗号分隔的地址上,这是预期行为。
但有个边界 case 需要确认:如果用户配置的是
`apollo://127.0.0.1:8080/config1,192.168.1.1:8080/config2`(不同节点部署在不同 context
path),当前实现会把两个 path 都丢掉(因为 `url.Host` 只取第一个,`url.Path` 只取最后一个节点的 path)。
建议在文档或注释中明确说明:**context path 必须对所有节点相同**,或者考虑在代码中检查并 warn 这种不一致配置。
##########
config_center/apollo/impl.go:
##########
@@ -222,10 +222,14 @@ func (c *apolloConfiguration)
getAddressWithProtocolPrefix(url *common.URL) stri
addr := regexp.MustCompile(`\s+`).ReplaceAllString(address, "")
parts := strings.Split(addr, ",")
addrs := make([]string, 0)
+ path := strings.Trim(url.Path, "/")
for _, part := range parts {
addr := part
+ if path != "" {
+ addr = strings.TrimRight(addr, "/") + "/" + path
+ }
if !strings.HasPrefix(part, apolloProtocolPrefix) {
Review Comment:
[P2] `strings.TrimRight(addr, "/")` 会把地址中所有尾部 `/` 都去掉,包括 `http://`
协议前缀添加前的原始地址。
当前流程:
1. `addr = part`(如 `127.0.0.1:8080/`)
2. `addr = strings.TrimRight(addr, "/") + "/" + path` →
`127.0.0.1:8080/config`
3. 加 `http://` 前缀 → `http://127.0.0.1:8080/config`
这个顺序是对的。但如果 `part` 本身已经带了 `http://` 前缀(如
`http://127.0.0.1:8080/`),`TrimRight` 不会误伤到 `http://` 中的 `/`,因为 `TrimRight`
只从右端开始 trim,`http://` 的 `/` 不在右端。
不过建议加个防御性注释说明这个顺序的依赖关系,避免后续维护者调整顺序时引入 bug。
--
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]