Documentation
¶
Overview ¶
Package goproxyclient provides a client for talking to Go module proxies.
Index ¶
- func IsNotFound(err error) bool
- type Client
- func (cl Client) Info(ctx context.Context, mod, ver string) (string, time.Time, map[string]json.RawMessage, error)
- func (cl Client) Latest(ctx context.Context, mod string) (string, time.Time, map[string]json.RawMessage, error)
- func (cl Client) List(ctx context.Context, mod string) ([]string, error)
- func (cl Client) Mod(ctx context.Context, mod, ver string) (io.ReadCloser, error)
- func (cl Client) Zip(ctx context.Context, mod, ver string) (io.ReadCloser, error)
- type CodeErr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNotFound ¶ added in v0.4.0
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 ¶
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 ¶
List lists the available versions of a Go module. The result is sorted in semver order (see semver.Sort).
type CodeErr ¶ added in v0.4.0
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.