将net.DialTimeout与特定的本地端口一起使用

I'm trying to use specific source IP port, but net.DialTimeout does not have laddr parameter

my_dial, err := net.DialTimeout("tcp", addr, 3*time.Second)
conn := tls.Client(my_dial, tlsconf)

Then I checked the document, the only method that support laddr is:

func DialIP(network string, laddr, raddr *IPAddr) (*IPConn, error)

But it returns net.IPConn instead of net.Conn.

Any ideas?

Dial and DialTimeout are just helpers around the net.Dialer type, which has all the available options documented.

You can set a local address and the timeout. The Dialer also has a DialContext method to use a context directly rather than a timeout if desired.

d := net.Dialer{
    LocalAddr: lAddr,
    Timeout: timeout,
}
conn, err := d.Dial(network, address)
...