mirror of
https://github.com/golang/go
synced 2024-11-17 18:44:44 -07:00
net: add conversion from AddrPort to TCPAddr to complement existing inverse
We already have various member functions of TCPAddr that return an AddrPort, but we don't have a helper function to go from a AddrPort to a TCPAddr. UDP has this, but it was left out of TCP. This commit adds the corresponding function. Updates #49298. Change-Id: I85732cf34f47c792fe13a6b4af64fd4b0e85d06a Reviewed-on: https://go-review.googlesource.com/c/go/+/362596 Trust: Jason A. Donenfeld <Jason@zx2c4.com> Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
1ec51087e5
commit
a01a6d6efe
@ -96,6 +96,17 @@ func ResolveTCPAddr(network, address string) (*TCPAddr, error) {
|
||||
return addrs.forResolve(network, address).(*TCPAddr), nil
|
||||
}
|
||||
|
||||
// TCPAddrFromAddrPort returns addr as a TCPAddr. If addr.IsValid() is false,
|
||||
// then the returned TCPAddr will contain a nil IP field, indicating an
|
||||
// address family-agnostic unspecified address.
|
||||
func TCPAddrFromAddrPort(addr netip.AddrPort) *TCPAddr {
|
||||
return &TCPAddr{
|
||||
IP: addr.Addr().AsSlice(),
|
||||
Zone: addr.Addr().Zone(),
|
||||
Port: int(addr.Port()),
|
||||
}
|
||||
}
|
||||
|
||||
// TCPConn is an implementation of the Conn interface for TCP network
|
||||
// connections.
|
||||
type TCPConn struct {
|
||||
|
Loading…
Reference in New Issue
Block a user