提交 cde19359 authored 作者: mooncake9527's avatar mooncake9527

rd

上级 6a77fc2d
......@@ -111,8 +111,8 @@ func initOthers() (err error) {
if conf.App.CacheType != "" {
logger.Info(fmt.Sprintf("[cache-%s] initialized", conf.App.CacheType))
}
rdt := conf.App.RegistryDiscoveryType
if rdt == "nacos" {
rdType := conf.Rd.Type
if rdType == "nacos" {
if err := nacosRegisterInstance(); err != nil {
return err
}
......@@ -136,32 +136,18 @@ func nacosRegisterInstance() (err error) {
c.Rd.Nacos.Password = c.ConfCenter.Nacos.Password
}
})
config.Read(func(c *config.Config) {
copier.Copy(&conf, c)
})
logger.Debug("[rd][nacos]", logger.Any("conf", conf.Rd.Nacos))
var nacosCli *nacos.NacosServiceClient
// if conf.ConfType == "nacos" {
// logger.Info("conf type is nacos, use nacos conf client sc & cc")
// cc := conf.NacosConfClient.GetCC()
// sc := conf.NacosConfClient.GetSC()
// nacosCli, err = nacos.New(&conf.Rd.Nacos, cc, sc)
// if err != nil {
// return xerror.Wrap(err, "nacos new client failed")
// }
// } else {
// logger.Info("conf type is not nacos, use nacos conf to new a conf client")
nacosCli, err = nacos.NewWithConfig(&conf.Rd.Nacos)
if err != nil {
if nacosCli, err = nacos.NewWithConfig(&conf.Rd.Nacos); err != nil {
return xerror.Wrap(err, "nacos new client failed")
}
// }
if err := nacosCli.Register(); err != nil {
return xerror.Wrap(err, "nacos register instance failed")
}
config.Write(func(c *config.Config) {
global.NacosCli = nacosCli
global.G.NacosCli = nacosCli
})
return nil
}
......
......@@ -15,7 +15,6 @@ app:
trace:
enable: false
samplingRate: 1.0
registryDiscoveryType: ""
cacheType: "memory"
webLog:
enable: true
......@@ -59,6 +58,7 @@ logger:
isCompression: true
rd:
type: nacos # nacos、zookeeper...
nacos:
ips: 192.168.1.140
port: 8848
......
......@@ -135,6 +135,7 @@ type ConfCenter struct {
}
type Rd struct {
Type string `yaml:"type" json:"type"`
Nacos NacosSvcConfig `yaml:"nacos" json:"nacos"`
}
......@@ -225,12 +226,11 @@ type App struct {
CacheType string `yaml:"cacheType" json:"cacheType"`
Middleware Middleware `yaml:"middleware" json:"middleware"`
Env string `yaml:"env" json:"env"`
Host string `yaml:"host" json:"host"`
Name string `yaml:"name" json:"name"`
RegistryDiscoveryType string `yaml:"registryDiscoveryType" json:"registryDiscoveryType"` // e.g. nacos, consul , close if empty
Version string `yaml:"version" json:"version"`
IPRateLimiter IPRateLimiter `yaml:"ipRateLimiter" json:"ipRateLimiter"`
Env string `yaml:"env" json:"env"`
Host string `yaml:"host" json:"host"`
Name string `yaml:"name" json:"name"`
Version string `yaml:"version" json:"version"`
IPRateLimiter IPRateLimiter `yaml:"ipRateLimiter" json:"ipRateLimiter"`
HideSensitiveFields string `yaml:"hideSensitiveFields" json:"hideSensitiveFields"`
ConfPath string `yaml:"-" json:"confPath"`
......
......@@ -2,6 +2,8 @@ package global
import "gitlab.wanzhuangkj.com/tush/xpkg/rd/nacos"
var (
type g struct {
NacosCli *nacos.NacosServiceClient
)
}
var G = &g{}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论