gomod

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package gomod is the library behind the gomod command line: the HTTP client, request shaping, and typed data models for the Go Module Proxy (proxy.golang.org).

The Client sets a real User-Agent, paces requests to 200 ms by default, and retries 429/5xx responses with exponential backoff.

Index

Constants

View Source
const DefaultBaseURL = "https://" + Host

DefaultBaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "gomod/dev (+https://github.com/tamnd/gomod-cli)"

DefaultUserAgent identifies the client to proxy.golang.org.

View Source
const Host = "proxy.golang.org"

Host is the proxy hostname; the URI driver in domain.go claims it.

Variables

View Source
var ErrNotFound = fmt.Errorf("not found")

ErrNotFound is returned when the proxy returns 404 for a module or version.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	// Rate is the minimum gap between requests. Zero means no pacing.
	Rate    time.Duration
	Retries int
	// contains filtered or unexported fields
}

Client talks to proxy.golang.org over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults.

func (*Client) Get

func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)

Get fetches rawURL and returns the body bytes. It paces and retries.

func (*Client) Info

func (c *Client) Info(ctx context.Context, module, version string) (*ModuleInfo, error)

Info returns version info for a specific version of a module.

func (*Client) Latest

func (c *Client) Latest(ctx context.Context, module string) (*ModuleInfo, error)

Latest returns the latest version info for the given module path.

func (*Client) Mod

func (c *Client) Mod(ctx context.Context, module, version string) (*ModContent, error)

Mod returns the go.mod content for a specific version of a module.

func (*Client) Versions

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

Versions returns all known versions for the given module path.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Retries   int
	Timeout   time.Duration
}

Config holds constructor parameters.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type Domain

type Domain struct{}

Domain is the gomod driver.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns a module path or proxy URL into a (type, id) pair.

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate is the inverse: the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type ModContent

type ModContent struct {
	Module  string `json:"module"`
	Version string `json:"version"`
	Content string `json:"content"`
}

ModContent is returned by the mod command: the raw go.mod text.

type ModuleInfo

type ModuleInfo struct {
	Module  string `json:"module"`
	Version string `json:"version"`
	Time    string `json:"time,omitempty"`
}

ModuleInfo is returned by the latest and info commands.

Jump to

Keyboard shortcuts

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