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
proposal: net/netip: add Unmap() to netip.Is4() #49970
Comments
Note that Using both packages is a bit awkward but I expect most callers should migrate to |
Thanks Matt, your example is more concise and it better illustrates the point I'm trying to make. You need to add: |
Is this still needed then? |
Yes. In a nutshell, I'm looking for the possibility to change: ip.Unmap().Is4()
ip.Unmap().Is6() to ip.Is4()
ip.Is6() By doing |
ip.Is4() and ip.Unmap().Is4() are asking different, both completely reasonable questions. Is there anything unclear in the docs? It sounds like you found what you wanted and just wish it was shorter. |
Thank Russ, I agree both forms answer different questions. In my limited experience, users will use What if both |
This does exist today as https://pkg.go.dev/net/netip#Addr.Is4In6. |
Good catch! In fact Bottom line is I personally believe, so take it with a grain of salt, people won't care as much about whether the address is mapped or not, so why not make it simpler for the potential most popular use case, which is finding out what type of IP address it is: IPv4 or IPv6. Thanks |
This proposal has been added to the active column of the proposals project |
Based on the discussion above, this proposal seems like a likely decline. |
Understood. This is just a nice to have. Thanks for taking the time to discuss it. |
No change in consensus, so declined. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
This is for Go 1.18
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Currently to check if an IP address
ip
is an IPv4, you have to doip.Unmap().Is4()
, as IPv4 addresses are mapped into 128 bits, so you first need toUnmap
it, to then use the functionIs4
.For IPv6 you can simply do
ip.Is6()
, butip.Unmap().Is6()
will also work.This is an example: https://go.dev/play/p/slX6Bjf9Ee1?v=gotip
What did you expect to see?
I'm just wondering if there is a chance to have either
Unmap
called inside theIs4
andIs6
functions, or have a new API that is consistent for v4 and v6, so we can do:ip.IsV4()
orip.IsV6()
for example.What did you see instead?
Not a biggie, just a minor cosmetic thing for very picky people like me.
The text was updated successfully, but these errors were encountered: