1 Star 0 Fork 0

common_go/config

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

config

配置文件加载、读取是一个服务启动时必不可少的关键步骤,config 是封装的简单、易用的配置管理工具,具有以下特点:

  • 支持ini、yaml格式
  • 多种指定配置文件位置方法
  • 一次加载、内存缓存,读取速度快
  • 支持配置项与指定结构体转化
  • 支持自定义多配置文件加载、读取

安装

go get gitee.com/common_go/config

默认路径:

conf/conf.ini

修改配置路径

config.SetConfigPath("/home/dev/conf.ini")

重新设置路径后,下次再读取配置便会切换到新的配置源。

配置示例:

[goconfig]
name = goconfig
hosts = 127.0.0.1 127.0.0.2 127.0.0.3 

[goconfigStringMap]
name = goconfig
host = 127.0.0.1

[goconfigArrayMap]
name = goconfig1 goconfig2

[goconfigObject]
max=101
port=9099
rate=1.01
hosts=127.0.0.1 127.0.0.2
timeout=5s

读取示例:

//获取指定section下指定key的值
func GetConf(sec, key string) string
//获取指定section下指定key的值,不存在则返回默认值
func GetConfDefault(sec, key, def string) string
//获取指定section下指定key的slice类型值
func GetConfs(sec, key string) []string
//获取指定section下所有配置,返回map[string]string类型
func GetConfStringMap(sec string) (ret map[string]string)
//获取指定section下所有配置,返回map[string][]string类型
func GetConfArrayMap(sec string) (ret map[string][]string)
//将指定section下配置与传入类型v进行转化
func ConfMapToStruct(sec string, v interface{}) error

空文件

简介

config 展开 收起
Go
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/common_go/config.git
git@gitee.com:common_go/config.git
common_go
config
config
master

搜索帮助