mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-22 05:40:50 +02:00
39 lines
868 B
Go
39 lines
868 B
Go
![]() |
package registry
|
||
|
|
||
|
import (
|
||
|
"net"
|
||
|
"net/http"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type Client struct {
|
||
|
httpClient *http.Client
|
||
|
Timeout time.Duration
|
||
|
}
|
||
|
|
||
|
// NewClientWithHTTPClient returns a custom registry client useful for testing
|
||
|
func NewClientWithHTTPClient(httpClient *http.Client) *Client {
|
||
|
timeout := 30 * time.Second
|
||
|
return &Client{
|
||
|
httpClient,
|
||
|
timeout,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// NewClient returns a registry client with the default values
|
||
|
func NewClient() *Client {
|
||
|
tr := &http.Transport{
|
||
|
Proxy: http.ProxyFromEnvironment,
|
||
|
DialContext: (&net.Dialer{
|
||
|
Timeout: 30 * time.Second,
|
||
|
KeepAlive: 30 * time.Second,
|
||
|
}).DialContext,
|
||
|
ForceAttemptHTTP2: true,
|
||
|
MaxIdleConns: 100,
|
||
|
IdleConnTimeout: 90 * time.Second,
|
||
|
TLSHandshakeTimeout: 10 * time.Second,
|
||
|
ExpectContinueTimeout: 1 * time.Second,
|
||
|
}
|
||
|
return NewClientWithHTTPClient(&http.Client{Transport: tr})
|
||
|
}
|