From 856d4c3b773cf79eeaf57466a8113b191fb04721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 30 Jul 2024 11:48:39 +0200 Subject: [PATCH] do not nest conditions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- pkg/rgrpc/todo/pool/selector.go | 36 +++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/pkg/rgrpc/todo/pool/selector.go b/pkg/rgrpc/todo/pool/selector.go index a0e347c633..7c88368fba 100644 --- a/pkg/rgrpc/todo/pool/selector.go +++ b/pkg/rgrpc/todo/pool/selector.go @@ -102,24 +102,30 @@ func (s *Selector[T]) Next(opts ...Option) (T, error) { } target := s.id + // if the target is given as a recognized gRPC URI, skip registry lookup + // see https://github.com/grpc/grpc/blob/master/doc/naming.md#name-syntax prefix := strings.SplitN(s.id, ":", 2)[0] - switch prefix { - case "dns", "unix", "kubernetes": - // use target as is - default: + switch { + case prefix == "dns": + fallthrough + case prefix == "unix": + fallthrough + case prefix == "kubernetes": + // use target as is and skip registry lookup + case options.registry != nil: // use service registry to look up address - if options.registry != nil { - services, err := options.registry.GetService(s.id) - if err != nil { - return *new(T), fmt.Errorf("%s: %w", s.id, err) - } - - nodeAddress, err := registry.GetNodeAddress(services) - if err != nil { - return *new(T), fmt.Errorf("%s: %w", s.id, err) - } - target = nodeAddress + services, err := options.registry.GetService(s.id) + if err != nil { + return *new(T), fmt.Errorf("%s: %w", s.id, err) + } + + nodeAddress, err := registry.GetNodeAddress(services) + if err != nil { + return *new(T), fmt.Errorf("%s: %w", s.id, err) } + target = nodeAddress + default: + // if no registry is available, use the target as is } existingClient, ok := s.clientMap.Load(target)