Golang net.ListenTCP结构

The definition for the Golang function net.ListenTCP is:

func ListenTCP(net string, laddr *TCPAddr)

So it takes a string which is the type / version of TCP being used, and then a TCPAddr struct, which defines things like IP address to bind to, port to use etc.

However, I often see this function used like this:

net.ListenTCP("tcp", ":8080")

If the second parameter is looking for a TCPAddr struct / object, why does passing it a string work?

You are confusing net.ListenTCP with net.Listen.

func ListenTCP(net string, laddr *TCPAddr) (*TCPListener, error)

vs

func Listen(net, laddr string) (Listener, error)