代码拉取完成,页面将自动刷新
The env source reads config from environment variables
We expect environment variables to be in the standard format of FOO=bar
Keys are converted to lowercase and split on underscore.
DATABASE_ADDRESS=127.0.0.1
DATABASE_PORT=3306
Becomes
{
"database": {
"address": "127.0.0.1",
"port": 3306
}
}
Environment variables can be namespaced so we only have access to a subset. Two options are available:
WithPrefix(p ...string)
WithStrippedPrefix(p ...string)
The former will preserve the prefix and make it a top level key in the config. The latter eliminates the prefix, reducing the nesting by one.
Given ENVs of:
APP_DATABASE_ADDRESS=127.0.0.1
APP_DATABASE_PORT=3306
VAULT_ADDR=vault:1337
and a source initialized as follows:
src := env.NewSource(
env.WithPrefix("VAULT"),
env.WithStrippedPrefix("APP"),
)
The resulting config will be:
{
"database": {
"address": "127.0.0.1",
"port": 3306
},
"vault": {
"addr": "vault:1337"
}
}
Specify source with data
src := env.NewSource(
// optionally specify prefix
env.WithPrefix("GO_ADMIN"),
)
Load the source into config
// Create new config
conf := config.NewConfig()
// Load env source
conf.Load(src)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。