-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
net: add (*Resolver).ResolveIPAddr #30452
Comments
CC @mikioh @bradfitz @ianlancetaylor for |
I'm fine with that on principle. I'd never noticed you couldn't do IPv4- vs IPv6-specific lookups on Resolver before. That is, you can't do the equivalent of this today on func main() {
fmt.Println(net.ResolveIPAddr("ip4", "google.com"))
fmt.Println(net.ResolveIPAddr("ip6", "google.com"))
} The name |
It's unclear why we should add net.Resolver.ResolveIPAddr; why not just use LookupIPAddr and filter out what you want? ResolveIPAddr is just LookupIPAddr plus client-side filtering anyway. It's not any fewer bits on the wire. |
Sure, it can be done, but it would be nice to not make everyone who wants it re-implement it. |
I'm inclined to add this. @rsc, it is fewer bytes on the wire, in both directions: only asking for A or AAAA instead of both, and only getting answers for what we asked for. |
Today we have:
We need a new name for the function that takes a network. It would be good to keep the Lookup prefix common to all the other methods. Maybe it would be enough to shorten to "LookupIP":
where net is either "ip4" or "ip6". Do we really need IPAddr in the return type vs plain IP? Can DNS return a zone? |
@iangudger, any thoughts on the questions in the previous comment? If that API is OK then I think we're close to accepting the proposal. Thanks for your help and your patience. |
Sounds good to me. |
Howdy @iangudger, kindly pinging you as this proposal was approved almost a year ago. The Go tree closes in 3 weeks so if we’d like to see this for Go1.15, we’ve got a window of opportunity. Thank you! |
Change https://golang.org/cl/228641 mentions this issue: |
@rsc, @iangudger @bradfitz @andybons and @golang/proposal-review, I just gave @iangudger a code review in https://go-review.googlesource.com/c/go/+/228641/ and I realized that perhaps the name that we I think @bradfitz's suggestion in #30452 (comment) of
might be the best suited, or
would suffice. The code otherwise LGTM, but I think that the name will make or break us and inconsistencies might make it harder later on for users to navigate through the net package. Thank you. |
We never got an answer on @rsc's question:
If not, then we could just return |
AAAA records cannot contain a zone, so I think |
Phew. That's what I thought & hoped. (Was worried I missed some RFC.) Let's go with |
Previously, looking up only IPv4 or IPv6 addresses was only possible with DefaultResolver via ResolveIPAddr. Add this functionality to the Resolver type with a new method, LookupIP. This largely brings Resolver functionally to parity with the global functions. The name LookupIP is used over ResolveIPAddr to be consistent with the other Resolver methods. There are two main benefits to (*Resolver).LookupIP over (*Resolver).LookupHost. First is an ergonomic benefit. Wanting a specific family of address is common enough to justify a method, evident by the existence of ResolveIPAddr. Second, this opens the possibility of not performing unnecessary DNS requests when only a specific family of addresses are needed. This optimization is left to follow up work. Updates #30452 Change-Id: I241f61019588022a39738f8920b0ddba900cecdd Reviewed-on: https://go-review.googlesource.com/c/go/+/228641 Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
Previously, looking up only IPv4 or IPv6 addresses was only possible with DefaultResolver via ResolveIPAddr. Add this functionality to the Resolver type with a new method, LookupIP. This largely brings Resolver functionally to parity with the global functions. The name LookupIP is used over ResolveIPAddr to be consistent with the other Resolver methods. There are two main benefits to (*Resolver).LookupIP over (*Resolver).LookupHost. First is an ergonomic benefit. Wanting a specific family of address is common enough to justify a method, evident by the existence of ResolveIPAddr. Second, this opens the possibility of not performing unnecessary DNS requests when only a specific family of addresses are needed. This optimization is left to follow up work. Updates golang#30452 Change-Id: I241f61019588022a39738f8920b0ddba900cecdd Reviewed-on: https://go-review.googlesource.com/c/go/+/228641 Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
Should CL 228641 have closed this issue? |
As far as I can tell, this is done. Thanks. |
In the net package, there are two classes of DNS functions: LookupXxx and ResolveXxx. The net.Resolver type implements the LookupXxx functions as methods, but not the ResolveXxx functions. The ResolveXxx functions are similar to LookupHost, except they allow specifying a network. Adding the ResolveXxx functions as methods will allow a net.Resolver to fully replace the global DNS functions.
The text was updated successfully, but these errors were encountered: