Skip to content

Commit

Permalink
do not nest conditions
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Jul 30, 2024
1 parent a27e907 commit f41db26
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions pkg/rgrpc/todo/pool/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f41db26

Please sign in to comment.