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

feat(config): reading from env variables #474

Merged
merged 3 commits into from
Nov 13, 2024

Conversation

choyri
Copy link
Contributor

@choyri choyri commented Nov 10, 2024

The format of environment variables is as follows:

NZ_OAUTH2_TYPE=github
NZ_OAUTH2_ADMIN=foo
NZ_OAUTH2_CLIENTID=xxx
NZ_OAUTH2_CLIENTSECRET=yyy

In addition, it doesn't panic even if the config file doesn't exist, so we can start it more simply as a cloud service.

}
}

err := c.k.Load(env.Provider("NZ_", ".", func(s string) string {
Copy link
Member

Choose a reason for hiding this comment

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

同时有文件和env哪个优先级更高

Copy link
Contributor Author

Choose a reason for hiding this comment

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

根据 koanf 的文档描述,按加载顺序;在这个修改中,如果目标配置文件存在,会先加载,而后再加载环境变量,因此,环境变量优先级更高。

koanf does not impose any ordering on loading config from various providers. Every successive Load() or Merge() merges new config into the existing config. That is, it is possible to load environment variables first, then files on top of it, and then command line variables on top of it, or any such order.

@naiba
Copy link
Member

naiba commented Nov 13, 2024 via email

@choyri
Copy link
Contributor Author

choyri commented Nov 13, 2024

不可以喔 要以配置文件为主,要在线修改的

一般情况下不会有同时使用配置文件和环境变量的朋友吧?于我而言,是计划作为云服务部署的,只会配置环境变量,不会有配置文件存在,也不会在线修改配置。

不过这个服务既然支持在线修改配置,那确实也是可以这样定义优先级。

@naiba naiba merged commit 9b6d8ad into nezhahq:master Nov 13, 2024
6 checks passed
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.

2 participants