1 Star 0 Fork 1

yoyofx / cfg

forked from qiqi / cfg 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
qiqi 提交于 2021-01-29 11:26 . 文档更新

一个简单的 toml/yaml 配置读取包

这是一个非常简单的配置读取包,功能非常单一,使用非常简单;

安装

gitee.com/zhucheer/cfg

使用

cfgHandler, _ := cfg.New("./config.toml") //设置配置文件地址
value := cfgHandler.GetInt("database.connection_max") //读取toml配置节点

Nacos 支持

1.首先,我们需要在项目中初始化 Nacos Client。

clientConfig := *constant.NewClientConfig(
		constant.WithNotLoadCacheAtStart(true),
		constant.WithLogDir("./nacos/log"),
		constant.WithCacheDir("./nacos/cache"),
		constant.WithRotateTime("1h"),
		constant.WithMaxAge(6),
		constant.WithLogLevel("info"),
		constant.WithNamespaceId(""),
		constant.WithUsername(),
		constant.WithPassword()
	)
	configClient, _ := clients.NewConfigClient(
		vo.NacosClientParam{
			ClientConfig: &clientConfig,
			ServerConfigs: []constant.ServerConfig{
				{
					IpAddr:      "106.55.145.120",
					ContextPath: "/nacos",
					Port:        8848,
					Scheme:      "http",
				},
			},
		},
	)

// clientConfig,configClient可以配置成全局变量,在需要使用nacos的地方直接调用

2.将nacos配置实例化到cfg包的handler

    handler := NewNacos(&NacosBase{
		ConfigClient: configClient,
		GroupId:      "orange10",
		DataId:       "config.toml",
	})

	key := handler2.GetString("app.name")
Go
1
https://gitee.com/yoyofx/cfg.git
git@gitee.com:yoyofx/cfg.git
yoyofx
cfg
cfg
master

搜索帮助