Documentation
¶
Overview ¶
Package cargo holds the parts of the Cargo sparse registry protocol that proxy and group repositories need: request-path parsing, index file validation and merging, the registry config.json and its download template.
Index ¶
- Constants
- Variables
- func DownloadURL(dl, crate, version, cksum string) string
- func IndexPathFor(name string) string
- func MergeIndex(docs [][]byte) ([]byte, error)
- func RenderConfig(baseURL, repoName string, public bool) []byte
- func ValidCksum(s string) bool
- func VerifyConfig(spool io.ReadSeeker) error
- func VerifyIndex(spool io.ReadSeeker) error
- type Config
- type Entry
- type Kind
- type Path
Constants ¶
const MaxIndexBytes = 64 << 20
MaxIndexBytes bounds one index file read into memory. The largest crates have a few thousand versions, a few MiB of index.
Variables ¶
var ErrBadPath = errors.New("not a cargo registry path")
ErrBadPath is returned for a path that is not a registry request.
Functions ¶
func DownloadURL ¶
DownloadURL expands a registry's "dl" template for one crate version as cargo does: the markers {crate}, {version}, {prefix}, {lowerprefix} and {sha256-checksum} are substituted; without any marker the template is a base URL and "/{crate}/{version}/download" is appended.
func IndexPathFor ¶
IndexPathFor returns the path of crate's index file below the index root: "1/<n>", "2/<n>", "3/<c>/<n>" or "<ab>/<cd>/<n>". name must be ASCII.
func MergeIndex ¶
MergeIndex merges the index files docs of one crate (in member priority order): the union of their versions, the first file that lists a version providing its entry. Entries keep the order they first appear in.
func RenderConfig ¶
RenderConfig is the config.json a hosted, proxy or group repository serves: dl and api point at the repository under baseURL, the origin the client reached (absolute: cargo concatenates the dl template and never resolves it against the index URL), and a private repository makes cargo send its token with every request.
func ValidCksum ¶
ValidCksum reports whether s is a hex sha256 digest.
func VerifyConfig ¶
func VerifyConfig(spool io.ReadSeeker) error
VerifyConfig reports whether spool holds a registry config.json: a JSON object with a string "dl".
func VerifyIndex ¶
func VerifyIndex(spool io.ReadSeeker) error
VerifyIndex reports whether doc, read from spool, is a well-formed index file; it is the integrity check applied to an upstream answer before it is cached.
Types ¶
type Config ¶
type Config struct {
DL string `json:"dl"`
}
Config is the part of a registry config.json this package reads.
type Entry ¶
type Entry struct {
Vers string
Cksum string
// Pubtime is the entry's "pubtime", the publish time as the index states it
// (RFC 3339, UTC); "" when the index does not carry one. See Published.
Pubtime string
// Line is the raw JSON of the entry, without the newline.
Line []byte
}
Entry is one line of an index file.
func FindVersion ¶
FindVersion returns the entry of index doc whose version is exactly vers.
func ParseIndex ¶
ParseIndex parses the newline-delimited JSON of an index file. Every non-blank line must be a JSON object with string "name" and "vers"; an index file without entries is refused.