Reputation: 302
I have a TCPConn* that I've accepted from a TCPListener.acceptTCP. I'd like to get only the IP address (no port information) as a string or IP. What is the correct (i.e. minimal casting/string manipulation) way to accomplish that?
Upvotes: 6
Views: 1012
Reputation: 18430
To get the IP, as an IP object, the most straightforward way should be
tcpconn.RemoteAddr().(*net.TCPAddr).IP
There is nothing wrong with using type assertions, and in cases like this it's actually expected.
Upvotes: 8