package main import ( "fmt" "net" ) func main() { // Creating a TCPAddr for a TCP server listening on localhost and port 8080. addr := &net.TCPAddr{ IP: net.ParseIP("127.0.0.1"), Port: 8080, } // Printing the address in string format. fmt.Println(addr.String()) }
package main import ( "fmt" "net" ) func main() { // Parsing an IP address and port number as a string. addr, _ := net.ResolveTCPAddr("tcp", "192.168.1.100:8080") // Printing the address in string format. fmt.Println(addr.String()) }In this example, we use the ResolveTCPAddr function from the net package to parse a string representation of an IP address and port number. The resulting TCPAddr instance is printed as a string. Package Library: The TCPAddr structure and related functions are part of the standard Go "net" package.