Skip to content

Commit

Permalink
More readable code in .newServiceEndpoint()
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-v committed Oct 1, 2024
1 parent 17f5213 commit 3b27d25
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions services/src/main/java/io/scalecube/services/Microservices.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,14 @@ this, new ServiceDiscoveryOptions().serviceEndpoint(serviceEndpoint))
}

private ServiceEndpoint newServiceEndpoint(ServiceEndpoint serviceEndpoint) {
ServiceEndpoint.Builder builder = ServiceEndpoint.from(serviceEndpoint);
final ServiceEndpoint.Builder builder = ServiceEndpoint.from(serviceEndpoint);

int port = Optional.ofNullable(externalPort).orElse(serviceEndpoint.address().port());
final String finalHost =
Optional.ofNullable(externalHost).orElse(serviceEndpoint.address().host());
final int finalPort =
Optional.ofNullable(externalPort).orElse(serviceEndpoint.address().port());

// calculate local service endpoint address
Address newAddress =
Optional.ofNullable(externalHost)
.map(host -> Address.create(host, port))
.orElseGet(() -> Address.create(serviceEndpoint.address().host(), port));

return builder.address(newAddress).build();
return builder.address(Address.create(finalHost, finalPort)).build();
}

private Mono<GatewayBootstrap> startGateway(GatewayOptions options) {
Expand Down

0 comments on commit 3b27d25

Please sign in to comment.