-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Improve GetOutboundIP to work without internet access #1707
Improve GetOutboundIP to work without internet access #1707
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
Codecov Report
@@ Coverage Diff @@
## master #1707 +/- ##
==========================================
+ Coverage 61.22% 62.52% +1.29%
==========================================
Files 46 48 +2
Lines 7141 7519 +378
==========================================
+ Hits 4372 4701 +329
- Misses 2462 2498 +36
- Partials 307 320 +13
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
||
return localAddr.IP | ||
return nil |
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 think the caller will still crash the cli prog if you return nil here. The caller does an unconditional .String() in the help text..
The cli could use 127.0.0.1 or [::1] as bind address in this case, but may better fit on the caller side.
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.
It's safe to call (net.IP)(nil).String()
.
And if the caller really don't want a nil, it can check the return.
If the machine cannot access the internet, it returns a preferred IP address from network interfaces.