pkg/plugins/transport: export httpTransport, and return concrete type
Make NewHTTPTransport return a concrete type. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
77103c7c03
commit
dfd331b2c8
2 changed files with 8 additions and 8 deletions
|
@ -26,7 +26,7 @@ const (
|
||||||
dummyHost = "plugin.moby.localhost"
|
dummyHost = "plugin.moby.localhost"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTransport(addr string, tlsConfig *tlsconfig.Options) (transport.Transport, error) {
|
func newTransport(addr string, tlsConfig *tlsconfig.Options) (*transport.HTTPTransport, error) {
|
||||||
tr := &http.Transport{}
|
tr := &http.Transport{}
|
||||||
|
|
||||||
if tlsConfig != nil {
|
if tlsConfig != nil {
|
||||||
|
@ -77,7 +77,7 @@ func NewClientWithTimeout(addr string, tlsConfig *tlsconfig.Options, timeout tim
|
||||||
}
|
}
|
||||||
|
|
||||||
// newClientWithTransport creates a new plugin client with a given transport.
|
// newClientWithTransport creates a new plugin client with a given transport.
|
||||||
func newClientWithTransport(tr transport.Transport, timeout time.Duration) *Client {
|
func newClientWithTransport(tr *transport.HTTPTransport, timeout time.Duration) *Client {
|
||||||
return &Client{
|
return &Client{
|
||||||
http: &http.Client{
|
http: &http.Client{
|
||||||
Transport: tr,
|
Transport: tr,
|
||||||
|
|
|
@ -6,18 +6,18 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// httpTransport holds an http.RoundTripper
|
// HTTPTransport holds an [http.RoundTripper]
|
||||||
// and information about the scheme and address the transport
|
// and information about the scheme and address the transport
|
||||||
// sends request to.
|
// sends request to.
|
||||||
type httpTransport struct {
|
type HTTPTransport struct {
|
||||||
http.RoundTripper
|
http.RoundTripper
|
||||||
scheme string
|
scheme string
|
||||||
addr string
|
addr string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHTTPTransport creates a new httpTransport.
|
// NewHTTPTransport creates a new HTTPTransport.
|
||||||
func NewHTTPTransport(r http.RoundTripper, scheme, addr string) Transport {
|
func NewHTTPTransport(r http.RoundTripper, scheme, addr string) *HTTPTransport {
|
||||||
return httpTransport{
|
return &HTTPTransport{
|
||||||
RoundTripper: r,
|
RoundTripper: r,
|
||||||
scheme: scheme,
|
scheme: scheme,
|
||||||
addr: addr,
|
addr: addr,
|
||||||
|
@ -26,7 +26,7 @@ func NewHTTPTransport(r http.RoundTripper, scheme, addr string) Transport {
|
||||||
|
|
||||||
// NewRequest creates a new http.Request and sets the URL
|
// NewRequest creates a new http.Request and sets the URL
|
||||||
// scheme and address with the transport's fields.
|
// scheme and address with the transport's fields.
|
||||||
func (t httpTransport) NewRequest(path string, data io.Reader) (*http.Request, error) {
|
func (t HTTPTransport) NewRequest(path string, data io.Reader) (*http.Request, error) {
|
||||||
if !strings.HasPrefix(path, "/") {
|
if !strings.HasPrefix(path, "/") {
|
||||||
path = "/" + path
|
path = "/" + path
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue