https://github.com/520mianxiangduixiang520/duckcfg
A simpler and more unified way to read configuration files.
https://github.com/520mianxiangduixiang520/duckcfg
config golang json yaml
Last synced: 4 months ago
JSON representation
A simpler and more unified way to read configuration files.
- Host: GitHub
- URL: https://github.com/520mianxiangduixiang520/duckcfg
- Owner: 520MianXiangDuiXiang520
- License: mit
- Created: 2023-11-07T17:00:01.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-10T16:12:10.000Z (over 1 year ago)
- Last Synced: 2025-01-17T00:47:18.681Z (5 months ago)
- Topics: config, golang, json, yaml
- Language: Go
- Homepage: https://pkg.go.dev/github.com/520MianXiangDuiXiang520/duckCfg
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# duckCfg
A simpler and more unified way to read configuration files.
[中文](./README_ZH.md)
[](https://pkg.go.dev/github.com/520MianXiangDuiXiang520/duckCfg)
## Usage
```shell
go get github.com/520MianXiangDuiXiang520/duckCfg
``````go
package duckcfg_testimport (
"fmt"
"github.com/520MianXiangDuiXiang520/duckCfg"
)func GetIntFormatDefault() {
err := duckcfg.InitConfig("./test_data/01.yaml")
if err != nil {
panic(err)
}
timeout := duckcfg.Cfg().GetIntFormatDefault("db.mongo.conn_timeout", 0)
fmt.Println(timeout) // 3
}```
If you want to read from JSON, you only need to modify the file name.
## Q&A
> Q: What if my key contains a dot?
> * Use a backslash to escape it, e.g., if your key is db.mongo, you can use db\\.mongo to read it. The same applies to keys containing a backslash.> Q: My configuration file format is not supported.
> * You can define a FConfigLoader and use the Register function to register it.