func DialContextMiddleware(breaker DialBreaker) TransportMiddleware {
	return func(transport *http.Transport) *http.Transport {
		dialer := &net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
		}
		transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
			if !breaker.Allowed(addr) {
				return nil, errors.Errorf("access to address %q not allowed", addr)
			}

			return dialer.DialContext(ctx, network, addr)
		}
		return transport
	}
}
// DialContextMiddleware patches the default HTTP transport so
// that it fails when an attempt is made to dial a non-local
// host.
DialContextMiddleware patches the default HTTP transport so
that it fails when an attempt is made to dial a non-local
host.
// DialContextMiddleware patches the default HTTP transport so // that it fails when an attempt is made to dial a non - local // host .
func DialContextMiddleware(breaker DialBreaker) TransportMiddleware {
	return func(transport *http.Transport) *http.Transport {
		dialer := &net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
		}
		transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
			if !breaker.Allowed(addr) {
				return nil, errors.Errorf("access to address %q not allowed", addr)
			}
			return dialer.DialContext(ctx, network, addr)
		}
		return transport
	}
}
func DialContextMiddleware ( breaker DialBreaker ) TransportMiddleware { return func ( transport * http . Transport ) * http . Transport { dialer := & net . Dialer { Timeout : 30 * time . Second , KeepAlive : 30 * time . Second , } transport . DialContext = func ( ctx context . Context , network , addr string ) ( net . Conn , error ) { if ! breaker . Allowed ( addr ) { return nil , errors . Errorf ( " " , addr ) } return dialer . DialContext ( ctx , network , addr ) } return transport } }
DialContextMiddleware patches the default HTTP transport so
that it fails when an attempt is made to dial a non-local
host.
DialContextMiddleware patches the default HTTP transport so that it fails when an attempt is made to dial a non - local host .