From 7cc2f3dc3d322b7742544425974317d6a2efe189 Mon Sep 17 00:00:00 2001 From: kanade Date: Wed, 29 Oct 2025 17:29:59 +0800 Subject: [PATCH] =?UTF-8?q?refactor(client):=20=E7=A7=BB=E9=99=A4=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E7=9A=84=E6=9D=A1=E4=BB=B6=E5=88=A4=E6=96=AD=E5=92=8C?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除了针对 basePath 为 "erp" 的特殊处理逻辑 - 移除了重复的 consul discovery 初始化代码块 - 统一了客户端发现和配置逻辑 - 清理了无用的日志打印语句- 简化了 xClient 创建和存储流程 - 优化了 mutex 锁的使用范围 --- client/client.go | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/client/client.go b/client/client.go index 09a65c5..8b498d4 100644 --- a/client/client.go +++ b/client/client.go @@ -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() }