go-conf - Go 实现的轻量级的 config 库
MIT
跨平台
Google Go
软件简介
go-conf 是使用 Go 实现的一个轻量级的 config 库,参考了 ozzo-config 的设计,但具有更优的性能和支持动态移植配置的功能。
go-conf 采用 MIT 开源协议。
下载安装
go get github.com/syyongx/cconf
功能
-
从配置文件中读取配置,默认支持 JSON 格式文件,提供了接口,也可非常方便地扩展支持其他格式配置文件;
-
可将一个 go 的结构体数据直接动态移植到 config 实例中;
-
不需要提前构建结构体就可以直接获取你想要的数据;
快速开始
import github.com/syyongx/cconf
func main() {
c := cconf.New()
age := c.GetInt("age", 18)
name := c.Get("name").(string)
c.Set("email", "default@default.com")
email := c.GetString("email")
}
接口
New() *Conf
RegisterLoadFunc(typ string, fn loadFunc)
Load(files ...string) error
LoadWithPattern(pattern string) error
Set(key string, val interface{}) error
Get(key string, def ...interface{}) interface{}
GetString(key string, def ...string) string
GetInt(key string, def ...int) int
GetInt64(key string, def ...int64) int64
GetFloat(key string, def ...float64) float64
GetBool(key string, def ...bool) bool
SetStore(data ...interface{})
GetStore() interface{}
Register(name string, provider interface{}) error
Populate(v interface{}, key ...string) (err error)