type DialFunc … type Dialer … // NewDialer creates a new Dialer instance. // Equivalent to NewDialerWithTracker(dial, nil). func NewDialer(dial DialFunc) *Dialer { … } // NewDialerWithTracker creates a new Dialer instance. // // If dial is not nil, it will be used to create new underlying connections. // Otherwise net.DialContext is used. // If tracker is not nil, it will be used to track new underlying connections. // Otherwise NewConnectionTracker() is used. func NewDialerWithTracker(dial DialFunc, tracker *ConnectionTracker) *Dialer { … } type ConnectionTracker … // NewConnectionTracker returns a connection tracker for use with NewDialerWithTracker func NewConnectionTracker() *ConnectionTracker { … } // CloseAll forcibly closes all tracked connections. // // Note: new connections may get created before CloseAll returns. func (c *ConnectionTracker) CloseAll() { … } // Track adds the connection to the list of tracked connections, // and returns a wrapped copy of the connection that stops tracking the connection // when it is closed. func (c *ConnectionTracker) Track(conn net.Conn) net.Conn { … } // Dial creates a new tracked connection. func (d *Dialer) Dial(network, address string) (net.Conn, error) { … } // DialContext creates a new tracked connection. func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) { … } type closableConn … func (c *closableConn) Close() error { … }