goproxyclient

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2025 License: MIT Imports: 12 Imported by: 3

README

Goproxyclient

Go Reference Go Report Card Tests Coverage Status

This is goproxyclient, a library and command-line tool for communicating with a Go module proxy, such as the public one operated by Google at proxy.golang.org.

Installation

For the command-line tool:

go install github.com/bobg/goproxyclient/cmd/goproxyclient@latest

For the library:

go get github.com/bobg/goproxyclient@latest

Usage

For library usage please see the package doc.

Command-line usage:

goproxyclient [-proxy URL] COMMAND ARG ARG...

where COMMAND is one of info, latest, list, mod, and zip. If -proxy is given, it is the base URL of the Go module proxy server to query. The default is the first element of the GOPROXY environment variable, or https://proxy.golang.org if that’s not set.

The info command produces JSON-encoded metadata about each argument. Each argument must be in the form MODPATH@VERSION.

The latest command produces JSON-encoded metadata about the latest version of each argument. Each argument must be a bare module path.

The list command produces a sorted list of available versions for each argument. Each argument must be a bare module path.

The mod command produces the go.mod file for its argument, which must be in the form MODPATH@VERSION.

The zip command produces a zip file with the module contents for its argument, which must be in the form MODPATH@VERSION.

Documentation

Overview

Package goproxyclient provides a client for talking to Go module proxies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNotFound added in v0.4.0

func IsNotFound(err error) bool

IsNotFound tests an error to see if it is a CodeErr and has status code 404 (Not Found) or 410 (Gone).

Types

type Client

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

Client is a client for talking to a sequence of one or more Go module proxies. Create one with New.

func New

func New(goproxy string, hc *http.Client) Client

New creates a new Client talking to a sequence of one or more Go module proxies.

The proxies are specified as described for the GOPROXY environment variable at https://go.dev/ref/mod#goproxy-protocol. That string specifies a list of proxy URLs separated by commas (,) or pipes (|). For each query type, the proxies are tried in sequence, and the result of the first successful request is returned.

If a request is unsuccessful, then whether the next proxy in the sequence is tried depends on whether a comma or a pipe introduces the next proxy in the sequence:

  • If a comma, then the next proxy is tried only if the failure is a 404 (Not Found) or 410 (Gone) error.
  • If a pipe, then the next proxy is tried regardless of the failure.

This function ignores any entry in the input string that is "direct", "off", or empty. If no proxy URL is found, it uses https://proxy.golang.org by default.

If hc is non-nil, it will use that HTTP client for all requests, otherwise it will use a default HTTP client (but a distinct one from http.DefaultClient).

func (Client) Info

func (cl Client) Info(ctx context.Context, mod, ver string) (string, time.Time, map[string]json.RawMessage, error)

Info gets information about a specific version of a Go module. A Go module proxy produces a JSON object with Version and Time fields, and possibly others.

This function returns the canonical version string, the timestamp for that version, and a map of all the fields parsed from the JSON object.

The returned version may be different from the one supplied as an argument, which is not required to be canonical. (It may be a branch name or commit hash, for example.)

The values in the map are unparsed JSON that can be further decoded with calls to json.Unmarshal.

func (Client) Latest

func (cl Client) Latest(ctx context.Context, mod string) (string, time.Time, map[string]json.RawMessage, error)

Latest gets info about the latest version of a Go module. Its return values are the same as for Client.Info.

func (Client) List

func (cl Client) List(ctx context.Context, mod string) ([]string, error)

List lists the available versions of a Go module. The result is sorted in semver order (see semver.Sort).

func (Client) Mod

func (cl Client) Mod(ctx context.Context, mod, ver string) (io.ReadCloser, error)

Mod gets the go.mod file for a specific version of a Go module.

func (Client) Zip

func (cl Client) Zip(ctx context.Context, mod, ver string) (io.ReadCloser, error)

Zip gets the contents of a specific version of a Go module as a zip file.

type CodeErr added in v0.4.0

type CodeErr interface {
	error
	Code() int
}

CodeErr is the type of an error that has an associated HTTP status code. This interface is satisfied by mid.CodeErr from github.com/bobg/mid.

Directories

Path Synopsis
cmd
goproxyclient command

Jump to

Keyboard shortcuts

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