mirror of
https://github.com/containrrr/watchtower.git
synced 2026-01-30 04:35:15 +01:00
feat: move registry http calls to common client
This commit is contained in:
parent
9220b51665
commit
6c1dfecea3
7 changed files with 212 additions and 171 deletions
40
pkg/registry/client.go
Normal file
40
pkg/registry/client.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package registry
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"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,
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
return NewClientWithHTTPClient(&http.Client{Transport: tr})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue