Harry33t opened a new issue, #1083:
URL: https://github.com/apache/dubbo-go-samples/issues/1083

   ## 问题题描述
   
   我在本地测试 config_yaml sample 时,发现 README 中的 DUBBO_GO_CONFIG_PATH 示例使用了相对路径:
   ```
   export DUBBO_GO_CONFIG_PATH="../conf/dubbogo.yml"
   cd path_to_dubbogo-sample/config_yaml/go-server/cmd
   go run .
   ``` 
   这个命令只有在用户严格` cd`  到 `config_yaml/go-server/cmd`  目录后才可以正常工作。
   
   如果用户从仓库根目录运行,比方:
   
   > go run ./config_yaml/go-server/cmd/main.go
   
   那么相对路径 ```../conf/dubbogo.yml``` 就无法指向正确的配置文件,容易导致配置加载失败。
   
   
   ## 复现步骤
   
   在仓库根目录设置 README 中的相对配置路径:
   
   > export DUBBO_GO_CONFIG_PATH="../conf/dubbogo.yml"
   
   然后从仓库根目录启动 server:
   
   > go run ./config_yaml/go-server/cmd/main.go
   
   ### 实际结果
   
   程序无法按预期加载配置文件,因为 ../conf/dubbogo.yml 是相对于当前工作目录解析的,而不是相对于 main.go 所在目录解析的。
   
   对于第一次接触该 sample 的用户来说,这个问题不够直观,容易误以为是 Dubbo 配置或 Zookeeper 注册失败。
   
   ### 预期结果
   
   README 中的命令应该尽量不依赖用户当前工作目录,或者明确说明必须在哪个目录执行。
   
   ## 建议修复方式
   
   建议 README 使用从仓库根目录可执行的绝对路径示例,例如:
   ```
   export DUBBO_GO_CONFIG_PATH="$(pwd)/config_yaml/go-server/conf/dubbogo.yml"
   go run ./config_yaml/go-server/cmd/main.go
   ```
   client 也可以类似改为:
   ```
   export DUBBO_GO_CONFIG_PATH="$(pwd)/config_yaml/go-client/conf/dubbogo.yml"
   go run ./config_yaml/go-client/cmd/main.go
   ```
   如果需要兼容 Windows PowerShell,也可以补充:
   ```
   $env:DUBBO_GO_CONFIG_PATH = "$PWD\config_yaml\go-server\conf\dubbogo.yml"
   go run .\config_yaml\go-server\cmd\main.go
   ```
   ## 影响
   这是一个文档易用性问题,不一定阻塞所有用户运行 
sample,但会导致用户从不同目录执行命令时出现配置加载失败。对于新用户来说,错误原因不容易定位。如果这个修复方向可以接受,我可以继续提交 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