2017-08-10 14:21:42 +02:00
|
|
|
package netutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/kataras/golog"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Client returns a new http.Client using
|
2018-04-22 12:52:36 +02:00
|
|
|
// the "timeout" for open connection.
|
2017-08-10 14:21:42 +02:00
|
|
|
func Client(timeout time.Duration) *http.Client {
|
|
|
|
transport := http.Transport{
|
|
|
|
Dial: func(network string, addr string) (net.Conn, error) {
|
|
|
|
conn, err := net.DialTimeout(network, addr, timeout)
|
|
|
|
if err != nil {
|
|
|
|
golog.Debugf("%v", err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return conn, err
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
client := &http.Client{
|
|
|
|
Transport: &transport,
|
|
|
|
}
|
|
|
|
|
|
|
|
return client
|
|
|
|
}
|