-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ISSUE #47]Read configuration from environment variables #196
Conversation
src/api/constants.rs
Outdated
|
||
pub const ENV_NACOS_CLIENT_COMMON_APP_NAME: &str = "nacos.client.app.name"; | ||
|
||
pub const ENV_NACOS_CLIENT_AUTH_USER_NAME: &str = "nacos.client.username"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用大写下横线分割的如何? '.' 对于 shell 脚本也不友好。另外USERNAME 应该是可以连起来的英文字符 🫡
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用大写下横线分割的如何? '.' 对于 shell 脚本也不友好。另外USERNAME 应该是可以连起来的英文字符 🫡
@CherishCai
可以,值我都改成大写用下划线连接,其他的设计是否有啥问题?
设计思路:
- 环境变量的设置有两种方式:直接设置和放入文件中
- 通过指定环境变量文件位置和默认位置进行加载
- 加载后转换成HashMap给后续进行使用
- 设置变量的时候首先从环境变量中获取,环境变量不存在,在从静态变量HashMap中获取进行设置填充
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mxsm 会不会太多方式造成理解成本大呢?不如先支持环境变量获取,后续真有需求再添加配置文件方式
@@ -73,6 +73,7 @@ want = "0.3.0" | |||
dashmap = "5.4.0" | |||
home = "0.5.4" | |||
|
|||
dotenvy = "0.15" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dotenvy 建议仅用作测试用例,放于 dev-dependencies 下。
src/api/constants.rs
Outdated
|
||
pub const ENV_NACOS_CLIENT_COMMON_APP_NAME: &str = "nacos.client.app.name"; | ||
|
||
pub const ENV_NACOS_CLIENT_AUTH_USER_NAME: &str = "nacos.client.username"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mxsm 会不会太多方式造成理解成本大呢?不如先支持环境变量获取,后续真有需求再添加配置文件方式
Codecov ReportPatch coverage:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #196 +/- ##
==========================================
+ Coverage 15.65% 15.90% +0.25%
==========================================
Files 49 49
Lines 2805 2829 +24
==========================================
+ Hits 439 450 +11
- Misses 2366 2379 +13
☔ View full report in Codecov by Sentry. |
@CherishCai dotenvy这使用并不会影响,dotenvy这个工具只是多了一个附加的功能从文件中获取数据,然后设置到环境变量中。如果没有对应的文件的话就不会加载。同时里面也处理文件不存在的情况也不会报错。 不会增加理解成本 使用者不用关心。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
close #47