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:
Sebastiaan van Stijn 2023-07-18 12:23:47 +02:00
parent 77103c7c03
commit dfd331b2c8
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 8 additions and 8 deletions

View file

@ -26,7 +26,7 @@ const (
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{}
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.
func newClientWithTransport(tr transport.Transport, timeout time.Duration) *Client {
func newClientWithTransport(tr *transport.HTTPTransport, timeout time.Duration) *Client {
return &Client{
http: &http.Client{
Transport: tr,

View file

@ -6,18 +6,18 @@ import (
"strings"
)
// httpTransport holds an http.RoundTripper
// HTTPTransport holds an [http.RoundTripper]
// and information about the scheme and address the transport
// sends request to.
type httpTransport struct {
type HTTPTransport struct {
http.RoundTripper
scheme string
addr string
}
// NewHTTPTransport creates a new httpTransport.
func NewHTTPTransport(r http.RoundTripper, scheme, addr string) Transport {
return httpTransport{
// NewHTTPTransport creates a new HTTPTransport.
func NewHTTPTransport(r http.RoundTripper, scheme, addr string) *HTTPTransport {
return &HTTPTransport{
RoundTripper: r,
scheme: scheme,
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
// 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, "/") {
path = "/" + path
}