From e9a29be5ba8dfda7eb02f2d91d98b9cfe6b9985c Mon Sep 17 00:00:00 2001 From: baozhecheng Date: Tue, 23 Aug 2022 14:29:25 +0800 Subject: [PATCH] fix --- contrib/registry/consul/client.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/contrib/registry/consul/client.go b/contrib/registry/consul/client.go index a99d812b2..f2fdfefac 100644 --- a/contrib/registry/consul/client.go +++ b/contrib/registry/consul/client.go @@ -133,20 +133,14 @@ func (c *Client) Register(_ context.Context, svc *registry.ServiceInstance, enab TaggedAddresses: addresses, } - if len(checkAddresses) > 0 { + for _, address := range checkAddresses { host, portRaw, _ := net.SplitHostPort(checkAddresses[0]) port, _ := strconv.ParseInt(portRaw, 10, 32) asr.Address = host asr.Port = int(port) - } - - if c.registryPortByScheme != "" { - for _, address := range checkAddresses { - if !strings.HasPrefix(address, c.registryPortByScheme) { - continue - } - host, portRaw, _ := net.SplitHostPort(checkAddresses[0]) - port, _ := strconv.ParseInt(portRaw, 10, 32) + if strings.HasPrefix(address, c.registryPortByScheme) { + host, portRaw, _ = net.SplitHostPort(address) + port, _ = strconv.ParseInt(portRaw, 10, 32) asr.Address = host asr.Port = int(port) break