Go 实现的轻量级的 config 库 go-conf

码农软件 · 软件分类 · 其他开发相关 · 2019-10-16 09:29:24

软件介绍

go-conf 是使用 Go 实现的一个轻量级的 config 库,参考了 ozzo-config 的设计,但具有更优的性能和支持动态移植配置的功能。

go-conf 采用 MIT 开源协议。

下载安装

go get github.com/syyongx/cconf

功能

  1. 从配置文件中读取配置,默认支持 JSON 格式文件,提供了接口,也可非常方便地扩展支持其他格式配置文件;

  2. 可将一个 go 的结构体数据直接动态移植到 config 实例中;

  3. 不需要提前构建结构体就可以直接获取你想要的数据;

快速开始

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)

本文地址:https://codercto.com/soft/d/16866.html

The Web Designer's Idea Book

The Web Designer's Idea Book

Patrick Mcneil / How / 2008-10-6 / USD 25.00

The Web Designer's Idea Book includes more than 700 websites arranged thematically, so you can find inspiration for layout, color, style and more. Author Patrick McNeil has cataloged more than 5,000 s......一起来看看 《The Web Designer's Idea Book》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试