1 Star 0 Fork 0

最爱腿腿 / goimooc_common

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
config.go 747 Bytes
一键复制 编辑 原始数据 按行查看 历史
最爱腿腿 提交于 2024-04-28 14:18 . init
package common
import (
"github.com/go-micro/plugins/v4/config/source/consul"
"go-micro.dev/v4/config"
"strconv"
)
// GetConsulConfig 设置配置中心
func GetConsulConfig(host string, port int64, prefix string) (config.Config, error) {
consulSource := consul.NewSource(
// 设置配置中心的地址
consul.WithAddress(host+":"+strconv.FormatInt(port, 10)),
//设置前缀,不设置默认前缀 /micro/config
consul.WithPrefix(prefix),
// 是否移除前缀,这里是设置为true,表示可以不带前缀直接获取对应配置
consul.StripPrefix(true),
)
// 配置初始化
conf, err := config.NewConfig()
if err != nil {
return conf, err
}
// 加载配置
err = conf.Load(consulSource)
return conf, err
}
Go
1
https://gitee.com/fushi/goimooc_common.git
git@gitee.com:fushi/goimooc_common.git
fushi
goimooc_common
goimooc_common
8c6f2f55334a

搜索帮助