dengliming commented on a change in pull request #1656:
URL: https://github.com/apache/incubator-shenyu/pull/1656#discussion_r655436490
##########
File path:
shenyu-common/src/main/java/org/apache/shenyu/common/utils/IpUtils.java
##########
@@ -34,6 +34,18 @@ private IpUtils() {
* @return the host
*/
public static String getHost() {
+ return getHost(null);
+ }
+
+ /**
+ * Gets host.
+ *
+ * @param preferred host preferred str
+ * @return the host
+ */
+ public static String getHost(final String preferred) {
Review comment:
`getHost(final String filterPrefix)` maybe better.
##########
File path:
shenyu-common/src/main/java/org/apache/shenyu/common/utils/IpUtils.java
##########
@@ -44,11 +56,25 @@ public static String getHost() {
InetAddress inetAddress = (InetAddress)
addresses.nextElement();
String hostAddress = inetAddress.getHostAddress();
if (hostAddress.contains(".") &&
!inetAddress.isLoopbackAddress()) {
- hostIp = hostAddress;
- break;
+ if (first) {
+ firstHostIp = hostAddress;
+ first = false;
Review comment:
You don't need to check `first`.
```
if (firstHostIp == null) {
firstHostIp = hostAddress;
}
```
##########
File path:
shenyu-client/shenyu-client-dubbo/shenyu-client-apache-dubbo/src/main/java/org/apache/shenyu/client/apache/dubbo/ApacheDubboServiceBeanListener.java
##########
@@ -104,7 +104,7 @@ private MetaDataRegisterDTO buildMetaDataDTO(final
ServiceBean serviceBean, fina
String path = contextPath + shenyuDubboClient.path();
String desc = shenyuDubboClient.desc();
String serviceName = serviceBean.getInterface();
- String host = StringUtils.isBlank(this.host) ? IpUtils.getHost() :
this.host;
+ String host = IpUtils.getHost(this.host);
Review comment:
I think it would be better if `host` and `hostPrefix` were configured
separately.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]