https://github.com/yuanzhangcai/config
配置文件解析
https://github.com/yuanzhangcai/config
config env json toml yaml
Last synced: 5 months ago
JSON representation
配置文件解析
- Host: GitHub
- URL: https://github.com/yuanzhangcai/config
- Owner: yuanzhangcai
- License: gpl-3.0
- Created: 2020-07-14T04:06:50.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-04-20T07:04:07.000Z (about 5 years ago)
- Last Synced: 2023-08-20T13:49:40.343Z (almost 3 years ago)
- Topics: config, env, json, toml, yaml
- Language: Go
- Homepage:
- Size: 38.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# config
[](https://github.com/yuanzhangcai/config/actions)
[](https://codecov.io/gh/yuanzhangcai/config)
[](https://github.com/yuanzhangcai/config/blob/master/LICENSE)
配置文件解析,目前支持toml、yaml、json文件格式。支持多配置文件重载。默认初次加载所有环境变量。支持配置文件热更新。
example:
```
import github.com/yuanzhangcai/config
// 加载配置
config.LoadFile(configFilePath + "config.toml")
// 读取配置参数
value := config.GetString("key")
// 修改配置参数
config.Set("newKey", "value")
value := strut {
List []string `json:"list"`
Server string `json:"server"`
Count int `json:"count"`
}{}
err = Scan([]string{"db"}, &value)
```
性能压测:
```
goos: darwin
goarch: amd64
pkg: github.com/yuanzhangcai/config
BenchmarkGet/Get_______________-12 6036589 196 ns/op
BenchmarkGet/viper_Get_________-12 462037 2604 ns/op
BenchmarkGet/micro_config_Get__-12 4340478 275 ns/op
BenchmarkGet/beego_config_Get__-12 2691524 446 ns/op
BenchmarkGet/Parallel_Get______-12 18792312 68.7 ns/op
BenchmarkGet/Parallel_viper_Get-12 1757396 668 ns/op
BenchmarkGet/Parallel_micro_Get-12 13200244 87.0 ns/op
BenchmarkGet/Parallel_beego_Get-12 9161379 149 ns/op
```