-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate ArmeriaSettings.ip and add ArmeriaSettings.address #4598
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kojilin for the quick fix! 🙇♂️
public void setAddress(InetAddress address) { | ||
this.address = address; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should return this
like other setters?
final Collection<ServerPort> serverPorts = server.activePorts().values(); | ||
for (ServerPort sp : serverPorts) { | ||
final InetAddress address = sp.localAddress().getAddress(); | ||
Assertions.assertThat(address.isAnyLocalAddress() || address.isLoopbackAddress()).isTrue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Prefer static import for assertions.
Assertions.assertThat(address.isAnyLocalAddress() || address.isLoopbackAddress()).isTrue(); | |
assertThat(address.isAnyLocalAddress() || address.isLoopbackAddress()).isTrue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really nice! Thanks @kojilin ! 🙇 👍 🙇
* Network address to bind to. If not set, will bind to all addresses, e.g. {@code 0.0.0.0}. | ||
*/ | ||
@Nullable | ||
private InetAddress address; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit; do you mind also updating the example?
armeria/spring/boot2-autoconfigure/src/main/java/com/linecorp/armeria/spring/ArmeriaSettings.java
Line 51 in e376b8c
* - ip: 127.0.0.1 |
@@ -0,0 +1,8 @@ | |||
armeria: | |||
ports: | |||
- ip: 127.0.0.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional; I'm unsure if this would also work in windows, but I think it would be cool if we can check that non-ip addresses are also accepted
- ip: 127.0.0.1 | |
- address: localhost |
@@ -0,0 +1,61 @@ | |||
/* | |||
* Copyright 2020 LINE Corporation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Copyright 2020 LINE Corporation | |
* Copyright 2023 LINE Corporation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for adding the address. 😄
@@ -82,10 +83,18 @@ public class ArmeriaSettings { | |||
public static class Port { | |||
/** | |||
* IP address to bind to. If not set, will bind to all addresses, e.g. {@code 0.0.0.0}. | |||
* @deprecated Use {@link #address} instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a blank line between the doc and @deprecated
. 😉
public Port setIp(String ip) { | ||
this.ip = ip; | ||
return this; | ||
} | ||
|
||
/** | ||
* Returns the Network address that the {@link Server} uses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I guess we don't need to capitalize the word
* Returns the Network address that the {@link Server} uses. | |
* Returns the network address that the {@link Server} uses. |
@@ -0,0 +1,61 @@ | |||
/* | |||
* Copyright 2023 LINE Corporation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy new year. 🎉 🎉 🎉
final Collection<ServerPort> serverPorts = server.activePorts().values(); | ||
for (ServerPort sp : serverPorts) { | ||
final InetAddress address = sp.localAddress().getAddress(); | ||
assertThat(address.isAnyLocalAddress() || address.isLoopbackAddress()).isTrue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: are these values different depending on the OS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure, I just put 127.0.0.1 & 0.0.0.0 at yml, so keep test both
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ha, if so how about branching it so that we can be sure what the test actually means?
if ("127.0.0.1".equals(address.getHostAddress())) {
assertThat(...).isTrue();
} else {
// 0.0.0.0
assertThat(...).isTrue();
}
final String ip = p.getIp(); | ||
final int port = p.getPort(); | ||
if (ip != null && address != null) { | ||
throw new IllegalStateException("A port cannot have both IP and address: " + p); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we override Port.toString()
to properly create the message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just left one question. Thanks a lot, @kojilin! 😄
return "Port{" + | ||
"ip='" + ip + '\'' + | ||
", address=" + address + | ||
", iface='" + iface + '\'' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: It seems like we add ''
to only ip
and iface
. Is there any specific reason for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used Intellij to generate and looks like it adds '
or not by String or not.
Maybe I should use MoreObjects.toStringHelper
like others?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't know about it. 😄 It looks good now. Thanks!
Thanks a lot, @kojilin! 😄 |
Motivation:
Spring allows Users to specify a hostname because Spring converts the input to an InetAddress.
So we need to also allow users to specify a hostname.
Modifications:
Result: