pkgsite: golang.org/x/pkgsite/internal/proxy Index | Files

package proxy

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

Package proxy provides a client for interacting with a proxy.

Index

Package Files

client.go server.go test_helper.go

type Client Uses

type Client struct {
    // 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 Uses

func New(u string) (_ *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.

func NewClientForServer Uses

func NewClientForServer(s *Server) (*Client, func(), error)

NewClientForServer starts serving proxyMux locally. It returns a client to the server and a function to shut down the server.

func SetupTestClient Uses

func SetupTestClient(t *testing.T, modules []*Module) (*Client, func())

SetupTestClient creates a fake module proxy for testing using the given test version information. If modules is nil, it will default to hosting the modules in the testdata directory.

It returns a function for tearing down the proxy after the test is completed and a Client for interacting with the test proxy.

func (*Client) GetInfo Uses

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

GetInfo makes a request to $GOPROXY/<module>/@v/<requestedVersion>.info and transforms that data into a *VersionInfo.

func (*Client) GetMod Uses

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

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

func (*Client) GetZip Uses

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

GetZip 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) GetZipSize Uses

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

GetZipSize 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.GetInfo.

func (*Client) ListVersions Uses

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

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

type Module Uses

type Module struct {
    ModulePath string
    Version    string
    Files      map[string]string
    // contains filtered or unexported fields
}

Module represents a module version used by the proxy server.

type Server Uses

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

Server represents a proxy server containing the specified modules.

func NewServer Uses

func NewServer(modules []*Module) *Server

NewServer returns a proxy Server that serves the provided modules.

func (*Server) AddModule Uses

func (s *Server) AddModule(m *Module)

AddModule adds an additional module to the server.

func (*Server) AddRoute Uses

func (s *Server) AddRoute(route string, fn func(w http.ResponseWriter, r *http.Request))

AddRoute adds an additional handler to the server.

type VersionInfo Uses

type VersionInfo struct {
    Version string
    Time    time.Time
}

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

Package proxy imports 22 packages (graph) and is imported by 10 packages. Updated 2020-10-28. Refresh now. Tools for package owners.