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 function Network() for netip Addr to make it support the interface of net.Addr #56286
Comments
Hi @josharian @bradfitz and @neild, is there any comment or progress for this proposal? Thanks! |
net.IP does not have a Network() string method, so it does not seem like netip.Addr should have one either, It is confusing that netip.Addr is not a net.Addr, but it's not. |
This proposal has been added to the active column of the proposals project |
Hi @rsc , Thanks! Both |
net.Addr exists to be returned from methods in net.Conn, specifically LocalAddr and RemoteAddr. For the specific case of AddrPort and Prefix, there is no We could make netip.TCPAddrPort, but net.TCPConn would still not return that type. |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
Abstract
As there are many advantages for using package
net/netip
instead ofnet
IP related, many projects need to do such conversion since golang 1.18. More detail can be refer to blogBackground
There are structs in package
net
to handle IP address and port, such asnet.IP
,net.IPNet
,net.IPAddr
andnet.TCPAddr
, and there is an interface namedAddr
in packagenet
with 2 APIs:Network()
andString()
to handle above structs.And there are structs named
Addr
,Prefix
andAddrPort
in packagenet/netip
as well, and these struct have only implemented functionString()
.Design
Generally, implementation for networking address in package
net
can be replaced bynet/netip
with many advantages, and want packagenet/netip
can be used in more, such as using forListener interface
in packagenet
, they should be implemented the interfaceAddr
innet
.Implement the interface
Addr
in packagenet
can helpnet/netip
being used in more, so just implement the functionNetwork()
for structsAddr
andAddrPort
innet/netip
, like PR: #56264The text was updated successfully, but these errors were encountered: