refactor(client): 移除多余的条件判断和重复代码
- 删除了针对 basePath 为 "erp" 的特殊处理逻辑 - 移除了重复的 consul discovery 初始化代码块 - 统一了客户端发现和配置逻辑 - 清理了无用的日志打印语句- 简化了 xClient 创建和存储流程 - 优化了 mutex 锁的使用范围
This commit is contained in:
parent
d402297eb8
commit
7cc2f3dc3d
@ -61,33 +61,17 @@ func GetClient(s interface{}) (*RpcClient, error) {
|
||||
mutex.Lock()
|
||||
xClient, ok = mClient.Load(key)
|
||||
if !ok {
|
||||
log.Println(11111111111111111, basePath, servicePath)
|
||||
if basePath == "erp" {
|
||||
//d, err := consulClient.NewConsulDiscovery(basePath, servicePath, config.RpcConfig.RegistryServer, nil)
|
||||
d, err := client.NewPeer2PeerDiscovery("tcp@127.0.0.1:8082", "")
|
||||
if err != nil {
|
||||
return nil, errors.New("系统异常")
|
||||
}
|
||||
option := client.DefaultOption
|
||||
option.Retries = 3
|
||||
option.GenBreaker = func() client.Breaker {
|
||||
return client.NewConsecCircuitBreaker(2, 30*time.Second)
|
||||
}
|
||||
xClient = client.NewXClient(servicePath, client.Failover, client.RoundRobin, d, option)
|
||||
mClient.Store(key, xClient)
|
||||
} else {
|
||||
d, err := consulClient.NewConsulDiscovery(basePath, servicePath, config.RpcConfig.RegistryServer, nil)
|
||||
if err != nil {
|
||||
return nil, errors.New("系统异常")
|
||||
}
|
||||
option := client.DefaultOption
|
||||
option.Retries = 3
|
||||
option.GenBreaker = func() client.Breaker {
|
||||
return client.NewConsecCircuitBreaker(2, 30*time.Second)
|
||||
}
|
||||
xClient = client.NewXClient(servicePath, client.Failover, client.RoundRobin, d, option)
|
||||
mClient.Store(key, xClient)
|
||||
d, err := consulClient.NewConsulDiscovery(basePath, servicePath, config.RpcConfig.RegistryServer, nil)
|
||||
if err != nil {
|
||||
return nil, errors.New("系统异常")
|
||||
}
|
||||
option := client.DefaultOption
|
||||
option.Retries = 3
|
||||
option.GenBreaker = func() client.Breaker {
|
||||
return client.NewConsecCircuitBreaker(2, 30*time.Second)
|
||||
}
|
||||
xClient = client.NewXClient(servicePath, client.Failover, client.RoundRobin, d, option)
|
||||
mClient.Store(key, xClient)
|
||||
}
|
||||
mutex.Unlock()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user