package main import ( "fmt" "net" ) func main() { addr := net.TCPAddr{ IP: net.ParseIP("127.0.0.1"), Port: 8080, Zone: "", } fmt.Println(addr.Network()) // prints "tcp" fmt.Println(addr.String()) // prints "127.0.0.1:8080" }
package main import ( "fmt" "net" ) func main() { addr, err := net.ResolveUDPAddr("udp", "localhost:1234") if err != nil { fmt.Println(err) return } fmt.Println(addr.Network()) // prints "udp" fmt.Println(addr.String()) // prints "localhost:1234" }This example uses net.ResolveUDPAddr to resolve a UDP address for "localhost:1234". The resulting Addr object is printed using the Network and String functions. The package library for net.Addr is net.