client

package
v6.0.0-alpha.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package client provides a convenience Client that resolves URL schemes to transport implementations and provides Handshake/Connect methods.

Index

Constants

View Source
const (
	// FollowInitialRedirects follows redirects only for the initial
	// /info/refs discovery request.
	FollowInitialRedirects = xhttp.FollowInitialRedirects
	// FollowRedirects follows redirects for all requests.
	FollowRedirects = xhttp.FollowRedirects
	// NoFollowRedirects disables redirects for all requests.
	NoFollowRedirects = xhttp.NoFollowRedirects
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client resolves URL schemes to transport implementations.

func New

func New(opts ...Option) *Client

New creates a Client with built-in transports for file, git, ssh, http, and https schemes. Options customize authentication, proxying, dialing, and transport overrides.

func (*Client) Close

func (c *Client) Close() error

Close releases resources held by the client.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context, req *transport.Request) (transport.Conn, error)

Connect resolves the transport for the request URL scheme and opens a raw full-duplex connection. Returns ErrConnectUnsupported if the transport does not implement Connector (e.g. HTTP).

func (*Client) Handshake

func (c *Client) Handshake(ctx context.Context, req *transport.Request) (transport.Session, error)

Handshake resolves the transport for the request URL scheme and performs a pack protocol handshake.

func (*Client) Transport

func (c *Client) Transport(scheme string) (transport.Transport, error)

Transport returns the resolved transport for the given URL scheme.

type HTTPAuth

type HTTPAuth interface {
	Authorizer(*http.Request) error
}

HTTPAuth is implemented by HTTP authentication types whose Authorizer method can be used to mutate outgoing HTTP requests.

type Option

type Option func(*options)

Option configures a Client.

func WithCABundle

func WithCABundle(pem []byte) Option

WithCABundle sets a PEM-encoded CA certificate bundle for HTTPS connections. When set, only these CAs are trusted. Can be combined with WithInsecureSkipTLS.

func WithDialer

func WithDialer(fn transport.DialContextFunc) Option

WithDialer sets a custom dialer for SSH and Git TCP transports.

func WithHTTPAuth

func WithHTTPAuth(a HTTPAuth) Option

WithHTTPAuth sets HTTP authentication. The auth type's Authorizer method is called for each outgoing HTTP request.

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets the HTTP client used by the HTTP transport. When a custom client is set, WithInsecureSkipTLS, WithCABundle, and WithProxyURL/WithProxyEnvironment do not affect HTTP connections — configure them on the provided client directly.

func WithInsecureSkipTLS

func WithInsecureSkipTLS() Option

WithInsecureSkipTLS disables TLS certificate verification for HTTPS. Can be combined with WithCABundle.

func WithLoader

func WithLoader(l transport.Loader) Option

WithLoader sets the storage loader for the file transport.

func WithProxyEnvironment

func WithProxyEnvironment() Option

WithProxyEnvironment honors standard proxy environment variables (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, NO_PROXY) for all transports. For HTTP, this uses http.ProxyFromEnvironment. For SSH and Git TCP, this uses golang.org/x/net/proxy.FromEnvironmentUsing.

func WithProxyURL

func WithProxyURL(u *url.URL) Option

WithProxyURL routes all transport connections through the given proxy URL. For HTTP, this uses http.ProxyURL. For SSH and Git TCP, this uses golang.org/x/net/proxy.FromURL to wrap the underlying dialer.

func WithRedirectPolicy

func WithRedirectPolicy(policy RedirectPolicy) Option

WithRedirectPolicy sets the HTTP redirect policy. If unset, the HTTP transport defaults to FollowInitialRedirects.

func WithSSHAuth

func WithSSHAuth(a SSHAuth) Option

WithSSHAuth sets SSH authentication. The auth type's ClientConfig method is called for each SSH connection.

func WithTransport

func WithTransport(scheme string, tr transport.Transport) Option

WithTransport registers a custom transport for the given URL scheme. This overrides any built-in transport for that scheme.

type RedirectPolicy

type RedirectPolicy = xhttp.RedirectPolicy

RedirectPolicy controls how HTTP transports follow redirects.

type SSHAuth

type SSHAuth interface {
	ClientConfig(context.Context, *transport.Request) (*gossh.ClientConfig, error)
}

SSHAuth is implemented by SSH authentication types whose ClientConfig method can be used to produce an *ssh.ClientConfig for each request.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL