代码拉取完成,页面将自动刷新
The file source reads config from a file.
It uses the File extension to determine the Format e.g config.yaml
has the yaml format.
It does not make use of encoders or interpet the file data. If a file extension is not present
the source Format will default to the Encoder in options.
A config file format in json
{
"hosts": {
"database": {
"address": "10.0.0.1",
"port": 3306
},
"cache": {
"address": "10.0.0.2",
"port": 6379
}
}
}
Specify file source with path to file. Path is optional and will default to config.json
fileSource := file.NewSource(
file.WithPath("/tmp/config.json"),
)
To load different file formats e.g yaml, toml, xml simply specify them with their extension
fileSource := file.NewSource(
file.WithPath("/tmp/config.yaml"),
)
If you want to specify a file without extension, ensure you set the encoder to the same format
e := toml.NewEncoder()
fileSource := file.NewSource(
file.WithPath("/tmp/config"),
source.WithEncoder(e),
)
Load the source into config
// Create new config
conf := config.NewConfig()
// Load file source
conf.Load(fileSource)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。