1 Star 0 Fork 0

yyycoder / common

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

搜索帮助

53164aa7 5694891 3bd8fe86 5694891