Skip to content
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

Merged
merged 2 commits into from
Sep 21, 2023

Conversation

mxsm
Copy link
Contributor

@mxsm mxsm commented Sep 20, 2023

close #47


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";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用大写下横线分割的如何? '.' 对于 shell 脚本也不友好。另外USERNAME 应该是可以连起来的英文字符 🫡

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用大写下横线分割的如何? '.' 对于 shell 脚本也不友好。另外USERNAME 应该是可以连起来的英文字符 🫡

@CherishCai
可以,值我都改成大写用下划线连接,其他的设计是否有啥问题?
设计思路:

  1. 环境变量的设置有两种方式:直接设置和放入文件中
  2. 通过指定环境变量文件位置和默认位置进行加载
  3. 加载后转换成HashMap给后续进行使用
  4. 设置变量的时候首先从环境变量中获取,环境变量不存在,在从静态变量HashMap中获取进行设置填充

Copy link
Collaborator

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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dotenvy 建议仅用作测试用例,放于 dev-dependencies 下。


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";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mxsm 会不会太多方式造成理解成本大呢?不如先支持环境变量获取,后续真有需求再添加配置文件方式

@codecov-commenter
Copy link

Codecov Report

Patch coverage: 66.66% and project coverage change: +0.25% 🎉

Comparison is base (4b97fd3) 15.65% compared to head (49b86d0) 15.90%.

❗ 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     
Files Changed Coverage Δ
src/api/props.rs 48.48% <60.00%> (+3.32%) ⬆️
src/lib.rs 54.54% <68.18%> (-9.10%) ⬇️

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mxsm
Copy link
Contributor Author

mxsm commented Sep 21, 2023

@CherishCai dotenvy这使用并不会影响,dotenvy这个工具只是多了一个附加的功能从文件中获取数据,然后设置到环境变量中。如果没有对应的文件的话就不会加载。同时里面也处理文件不存在的情况也不会报错。 不会增加理解成本 使用者不用关心。

Copy link
Collaborator

@CherishCai CherishCai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CherishCai CherishCai merged commit 26f52ba into nacos-group:main Sep 21, 2023
4 checks passed
@mxsm mxsm deleted the nacos-47 branch September 21, 2023 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: 自定义传参 + ENV 环境变量读取
3 participants