代码拉取完成,页面将自动刷新
这是一个非常简单的配置读取包,功能非常单一,使用非常简单;
gitee.com/zhucheer/cfg
cfgHandler, _ := cfg.New("./config.toml") //设置配置文件地址
value := cfgHandler.GetInt("database.connection_max") //读取toml配置节点
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")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。