本文整理汇总了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
}
示例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)
}
}
示例3: EnableTransport
// Enable the passed http.Transport for Unix domain socket connections.
func EnableTransport(t *http.Transport) {
t.DialContext = WrapDialContext(t.DialContext)
}