| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 | package netimport (	"net")// Destination represents a network destination including address and protocol (tcp / udp).type Destination struct {	Network Network	Port    Port	Address Address}// DestinationFromAddr generates a Destination from a net address.func DestinationFromAddr(addr net.Addr) Destination {	switch addr := addr.(type) {	case *net.TCPAddr:		return TCPDestination(IPAddress(addr.IP), Port(addr.Port))	case *net.UDPAddr:		return UDPDestination(IPAddress(addr.IP), Port(addr.Port))	default:		panic("Net: Unknown address type.")	}}// TCPDestination creates a TCP destination with given addressfunc TCPDestination(address Address, port Port) Destination {	return Destination{		Network: Network_TCP,		Address: address,		Port:    port,	}}// UDPDestination creates a UDP destination with given addressfunc UDPDestination(address Address, port Port) Destination {	return Destination{		Network: Network_UDP,		Address: address,		Port:    port,	}}func (d Destination) NetAddr() string {	return d.Address.String() + ":" + d.Port.String()}func (d Destination) String() string {	return d.Network.URLPrefix() + ":" + d.NetAddr()}func (d Destination) IsValid() bool {	return d.Network != Network_Unknown}// AsDestination converts current Enpoint into Destination.func (p *Endpoint) AsDestination() Destination {	return Destination{		Network: p.Network,		Address: p.Address.AsAddress(),		Port:    Port(p.Port),	}}
 |