mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 10:27:06 +00:00
Update to 8.2.2 | Google reCAPTCHA. Read HISTORY.md
Former-commit-id: dc8ee74fa33b2fbc41659c9097955afb152d5a6f
This commit is contained in:
33
core/netutil/client.go
Normal file
33
core/netutil/client.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package netutil
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/kataras/golog"
|
||||
)
|
||||
|
||||
// Client returns a new http.Client using
|
||||
// the "timeout" for open connection and read-write operations.
|
||||
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
|
||||
}
|
||||
if err = conn.SetDeadline(time.Now().Add(timeout)); err != nil {
|
||||
golog.Debugf("%v", err)
|
||||
}
|
||||
return conn, err
|
||||
},
|
||||
}
|
||||
|
||||
client := &http.Client{
|
||||
Transport: &transport,
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
Reference in New Issue
Block a user