...
1
2 package sockets
3
4 import (
5 "errors"
6 "net"
7 "net/http"
8 "time"
9 )
10
11 const defaultTimeout = 10 * time.Second
12
13
14 var ErrProtocolNotAvailable = errors.New("protocol not available")
15
16
17
18
19
20
21
22
23 func ConfigureTransport(tr *http.Transport, proto, addr string) error {
24 switch proto {
25 case "unix":
26 return configureUnixTransport(tr, proto, addr)
27 case "npipe":
28 return configureNpipeTransport(tr, proto, addr)
29 default:
30 tr.Proxy = http.ProxyFromEnvironment
31 tr.DisableCompression = false
32 tr.DialContext = (&net.Dialer{
33 Timeout: defaultTimeout,
34 }).DialContext
35 }
36 return nil
37 }
38
View as plain text