Skip to content
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

Does `hostLookupOrder` function in `net/conf.go` need to check nil pointer? #39239

Closed
psy-core opened this issue May 25, 2020 · 2 comments
Closed

Comments

@psy-core
Copy link

@psy-core psy-core commented May 25, 2020

I just read the source code about hostLookupOrder function in net library:

if c.netGo || r.preferGo() {

I noticed that r.preferGo() not check if r is nil.

but the function canUseCgo in this conf.go just call it with this:

return c.hostLookupOrder(nil, "") == hostLookupCgo

which Resolver param is nil. Am i missing something?

@davecheney
Copy link
Contributor

@davecheney davecheney commented May 25, 2020

In Go it is ok to call a method on a nil value. net.Resolver deals with this internally

func (r *Resolver) preferGo() bool { return r != nil && r.PreferGo }

@psy-core
Copy link
Author

@psy-core psy-core commented May 25, 2020

That's incredible. I never thought It could be used like this. Thank you very much.

@psy-core psy-core closed this May 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.