2 Star 1 Fork 1

qiqi / cfg

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

一个简单的 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")

Comments ( 0 )

Sign in for post a comment

About

golang toml 配置文件读取 spread retract
Go
MIT
Cancel

Releases

No release

Contributors

All

Activities

load more
can not load any more
Go
1
https://gitee.com/zhucheer/cfg.git
git@gitee.com:zhucheer/cfg.git
zhucheer
cfg
cfg
master

Search