當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Transport.DialContext方法代碼示例

本文整理匯總了Golang中net/http.Transport.DialContext方法的典型用法代碼示例。如果您正苦於以下問題:Golang Transport.DialContext方法的具體用法?Golang Transport.DialContext怎麽用?Golang Transport.DialContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net/http.Transport的用法示例。


在下文中一共展示了Transport.DialContext方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: initTransport

// Initialise the http.Transport for go1.7+
func (ci *ConfigInfo) initTransport(t *http.Transport) {
	t.DialContext = func(ctx context.Context, network, address string) (net.Conn, error) {
		return dialContextTimeout(ctx, network, address, ci.ConnectTimeout, ci.Timeout)
	}
	t.IdleConnTimeout = 60 * time.Second
	t.ExpectContinueTimeout = ci.ConnectTimeout
}
開發者ID:marcopaganini,項目名稱:rclone,代碼行數:8,代碼來源:http_new.go

示例2: installHTTPDialShim

// installHTTPDialShim patches the default HTTP transport so
// that it fails when an attempt is made to dial a non-local
// host.
//
// Note that this is Go version dependent because in Go 1.7 and above,
// the DialContext field was introduced (and set in http.DefaultTransport)
// which overrides the Dial field.
func installHTTPDialShim(t *http.Transport) {
	t.DialContext = func(ctxt context.Context, network, addr string) (net.Conn, error) {
		if !OutgoingAccessAllowed && !isLocalAddr(addr) {
			return nil, fmt.Errorf("access to address %q not allowed", addr)
		}
		return ctxtDialer.DialContext(ctxt, network, addr)
	}
}
開發者ID:anastasiamac,項目名稱:utils,代碼行數:15,代碼來源:http-1_7.go

示例3: EnableTransport

// Enable the passed http.Transport for Unix domain socket connections.
func EnableTransport(t *http.Transport) {
	t.DialContext = WrapDialContext(t.DialContext)
}
開發者ID:hlandau,項目名稱:degoutils,代碼行數:4,代碼來源:client.go


注:本文中的net/http.Transport.DialContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。