import ( "net" "fmt" ) func main() { addr := &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8080} fmt.Println(addr.String()) }
import ( "net" "fmt" ) func main() { addr := &net.UDPAddr{IP: net.IPv6loopback, Port: 9000} fmt.Println(addr.String()) }In this example, we create a UDP address with an IPv6 loopback address and a port of 9000. We then use the String method to print the address in string form. The output would be "[::1]:9000".