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

C语言程序设计现代方法

C语言程序设计现代方法

K. N. King / 人民邮电出版社 / 2007-11 / 55.00元

《C语言程序设计现代方法》最主要的一个目的就是通过一种“现代方法”来介绍C语言,实现客观评价C语言、强调标准化C语言、强调软件工程、不再强调“手工优化”、强调与c++语言的兼容性的目标。《C语言程序设计现代方法》分为C语言的基础特性。C语言的高级特性、C语言标准库和参考资料4个部分。每章都有“问与答”小节,给出一系列与本章内容相关的问题及其答案,此外还包含适量的习题。一起来看看 《C语言程序设计现代方法》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码