package proxy

import "golang.org/x/pkgsite/internal/proxy"

Package proxy provides a client for interacting with a proxy.

Index

Constants

const DisableFetchHeader = "Disable-Module-Fetch"

Setting this header to true prevents the proxy from fetching uncached modules.

Types

type Client

type Client struct {

	// Client used for HTTP requests. It is mutable for testing purposes.
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

A Client is used by the fetch service to communicate with a module proxy. It handles all methods defined by go help goproxy.

func New

func New(u string, transport http.RoundTripper) (_ *Client, err error)

New constructs a *Client using the provided url, which is expected to be an absolute URI that can be directly passed to http.Get. The optional transport parameter is used by the underlying http client.

func (*Client) EscapedURL

func (c *Client) EscapedURL(modulePath, requestedVersion, suffix string) (_ string, err error)

func (*Client) FetchDisabled

func (c *Client) FetchDisabled() bool

FetchDisabled reports whether proxy fetch is disabled.

func (*Client) Info

func (c *Client) Info(ctx context.Context, modulePath, requestedVersion string) (_ *VersionInfo, err error)

Info makes a request to $GOPROXY/<module>/@v/<requestedVersion>.info and transforms that data into a *VersionInfo. If requestedVersion is internal.LatestVersion, it uses the proxy's @latest endpoint instead.

func (*Client) Mod

func (c *Client) Mod(ctx context.Context, modulePath, resolvedVersion string) (_ []byte, err error)

Mod makes a request to $GOPROXY/<module>/@v/<resolvedVersion>.mod and returns the raw data.

func (*Client) Versions

func (c *Client) Versions(ctx context.Context, modulePath string) (_ []string, err error)

Versions makes a request to $GOPROXY/<path>/@v/list and returns the resulting version strings.

func (*Client) WithCache

func (c *Client) WithCache() *Client

WithCache returns a new client that caches some RPCs.

func (*Client) WithFetchDisabled

func (c *Client) WithFetchDisabled() *Client

WithFetchDisabled returns a new client that sets the Disable-Module-Fetch header so that the proxy does not fetch a module it doesn't already know about.

func (*Client) Zip

func (c *Client) Zip(ctx context.Context, modulePath, resolvedVersion string) (_ *zip.Reader, err error)

Zip makes a request to $GOPROXY/<modulePath>/@v/<resolvedVersion>.zip and transforms that data into a *zip.Reader. <resolvedVersion> must have already been resolved by first making a request to $GOPROXY/<modulePath>/@v/<requestedVersion>.info to obtained the valid semantic version.

func (*Client) ZipSize

func (c *Client) ZipSize(ctx context.Context, modulePath, resolvedVersion string) (_ int64, err error)

ZipSize gets the size in bytes of the zip from the proxy, without downloading it. The version must be resolved, as by a call to Client.Info.

type VersionInfo

type VersionInfo struct {
	Version string
	Time    time.Time
}

A VersionInfo contains metadata about a given version of a module.

Source Files

cache.go client.go

Directories

PathSynopsis
internal/proxy/proxytestPackage proxytest supports testing with the proxy.
Version
v0.0.0-20250218150137-224a1368cf02 (latest)
Published
Feb 18, 2025
Platform
linux/amd64
Imports
17 packages
Last checked
2 months ago

Tools for package owners.