registry

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2016 License: MIT Imports: 14 Imported by: 1

Documentation

Overview

Package registry implements a CommonJS compliant package registry. See http://wiki.commonjs.org/wiki/Packages/Registry

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMemStats

func NewMemStats() *runtime.MemStats

NewMemStats aggregates and returns memory stats.

Types

type PackageDist

type PackageDist struct {
	Tarball string `json:"tarball"`
	Shasum  string `json:"shasum"`
}

PackageDist describes how a package can be downloaded.

type PackageDistTags

type PackageDistTags map[string]string

PackageDistTags represents the dist-tags of a package root object. It maps Common JS tags, such latest, to specific versions.

type PackageRemote

type PackageRemote struct {
	Name string `json:"name"`
	URL  string `json:"url"`
}

PackageRemote is the equivalent to `git remote -v`.

type PackageRoot

type PackageRoot struct {
	Name     string               `json:"name"`
	DistTags *PackageDistTags     `json:"dist-tags"`
	Versions *PackageRootVersions `json:"versions"`
}

PackageRoot represents a CommonJS package root document containing all available versions of a given package available in its local repository. The root object that describes all versions of a package MUST be a JSON object with the following fields: name: The name of the package. When both are decoded, this MUST match the “package name” portion of the URL. That is, packages with irregular characters in their names would be URL-Encoded in the request, and JSON-encoded in the data. So, a request to /%C3%A7%C2%A5%C3%A5%C3%B1%C3%AE%E2%88%82%C3%A9 would show a package root object with “\u00e7\u00a5\u00e5\u00f1\u00ee\u2202\u00e9” as the name, and would refer to the “ç¥åñî∂é” project. versions: An object hash of version identifiers to valid “package version url” responses: either URL strings or package descriptor objects. See http://wiki.commonjs.org/wiki/Packages/Registry#Package_Root_Object

func NewPackageRoot

func NewPackageRoot(name string, url string, repo *git.Repository, shaCache *ShaCache) (*PackageRoot, error)

NewPackageRoot creates a new CommonJS package root document.

type PackageRootVersions

type PackageRootVersions map[string]*PackageVersion

PackageRootVersions represents the versions map in a package root document that will be served when clients request a specific package, but no version.

type PackageStats

type PackageStats struct {
	Remotes []*PackageRemote `json:"remotes"`
}

PackageStats contains information about the underlying git repo of a package.

func NewPackageStats

func NewPackageStats(repo *git.Repository) (*PackageStats, error)

NewPackageStats create a package stats object, which contains information about the underlying git repository.

type PackageVersion

type PackageVersion map[string]interface{}

PackageVersion represents a specific version of a package, typically its package.json file. The Package Version Object is almost identical to the Package Descriptor object described in the CommonJS Packages specification. For the purposes of the package registry, the following fields are required. Note that some of these do not exist in the Packages specification. name: The package name. This MUST match the {package name} portion of the URL. version: The package version. This MUST match the {package version} portion of the URL. dist: An object hash with urls of where the package archive can be found. The key is the type of archive. At the moment the following archive types are supported, but more may be added in the future: tarball: A url to a gzipped tar archive containing a single folder with the package contents (including the package.json file in the root of said folder). See http://wiki.commonjs.org/wiki/Packages/Registry#Package_Version_Object

func NewPackageVersion

func NewPackageVersion(repo *git.Repository, id *git.Oid) (*PackageVersion, error)

NewPackageVersion creates a package root object (package.json) from a given Git Object id.

type Ping

type Ping struct{}

Ping represents the response to a ping request. Ping is simply an empty object used by npm ping.

func NewPing

func NewPing() *Ping

NewPing creates a new ping object.

type Registry

type Registry struct {
	Router   *httprouter.Router
	Storage  *storage.Storage
	Upstream *Upstream
	// contains filtered or unexported fields
}

Registry represents an Common JS registry server. A Registry does exposes a router, which can be bound to an arbitrary socket.

func New

func New(storageDir string, upstreamURL string, shaCacheSize int) (*Registry, error)

New create a new CommonJS registry.

func (*Registry) HandleMemStats

func (r *Registry) HandleMemStats(w http.ResponseWriter, req *http.Request,
	ps httprouter.Params) error

HandleMemStats retrieves the current memory stats.

func (*Registry) HandlePackageDownload

func (r *Registry) HandlePackageDownload(repo *git.Repository,
	w http.ResponseWriter, req *http.Request, ps httprouter.Params) error

HandlePackageDownload handles package downloads.

func (*Registry) HandlePackageRoot

func (r *Registry) HandlePackageRoot(repo *git.Repository,
	w http.ResponseWriter, req *http.Request, ps httprouter.Params) error

HandlePackageRoot handles requests to the package root URL. The package root url is the base URL where a client can get top-level information about a package and all of the versions known to the registry. A valid “package root url” response MUST be returned when the client requests {registry root url}/{package name}. See http://wiki.commonjs.org/wiki/Packages/Registry#package_root_url

func (*Registry) HandlePackageStats

func (r *Registry) HandlePackageStats(repo *git.Repository,
	w http.ResponseWriter, req *http.Request, ps httprouter.Params) error

HandlePackageStats retrieves the current memory stats.

func (*Registry) HandlePing

func (r *Registry) HandlePing(w http.ResponseWriter, req *http.Request,
	_ httprouter.Params) error

HandlePing responds with an empty JSON object. npm's ping command hits this endpoint.

func (*Registry) HandleRoot

func (r *Registry) HandleRoot(w http.ResponseWriter, req *http.Request,
	_ httprouter.Params) error

HandleRoot handles requests to the registry root URL. The root URL is the base of the package registry. Given this url, a name, and a version, a package can be uniquely identified, assuming it exists in the registry. When requested, the registry root URL SHOULD return a list of packages in the registry in the form of a hash of package names to package root descriptors. The package root descriptor MUST be either: an Object that would be valid for the “package root url” contents for the named package, or a string URL that should be used as the package root url. In the case of a string URL, it MAY refer to a different registry. In that case, a request for {registry root url}/{package name} SHOULD be EITHER a 301 or 302 redirect to the same URL as named in the string value, OR a valid “package root url” response. See http://wiki.commonjs.org/wiki/Packages/Registry#registry_root_url

func (*Registry) HandleStats

func (r *Registry) HandleStats(w http.ResponseWriter, req *http.Request,
	ps httprouter.Params) error

HandleStats retrieves the current memory stats.

type Root

type Root map[string]string

Root maps package names to package root descriptors. In this context, package root descriptors are URLs to package root documents. The root URL is the base of the package registry. Given this url, a name, and a version, a package can be uniquely identified, assuming it exists in the registry. When requested, the registry root URL SHOULD return a list of packages in the registry in the form of a hash of package names to package root descriptors. The package root descriptor MUST be either: an Object that would be valid for the “package root url” contents for the named package, or a string URL that should be used as the package root url. In the case of a string URL, it MAY refer to a different registry. In that case, a request for {registry root url}/{package name} SHOULD be EITHER a 301 or 302 redirect to the same URL as named in the string value, OR a valid “package root url” response. See http://wiki.commonjs.org/wiki/Packages/Registry#registry_root_url

func NewRoot

func NewRoot(storage *storage.Storage, url string) (*Root, error)

NewRoot creates a new CommonJS registry root document from a given storage directory by reading in the repositories that are available in the storage dir.

type ShaCache

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

ShaCache serves as an adapter for an immutable LRU cache. Git object ids are cryptographically unique, therefore there is no need to "manually" remove items from the underlying LRU cache.

func NewShaCache

func NewShaCache(size int) (*ShaCache, error)

NewShaCache creates a new LRU cache used for mapping Git object ids to respective SHA1 sums.

func (*ShaCache) Add

func (c *ShaCache) Add(id git.Oid, shasum string) bool

Add populates the cache with the given Git object id.

func (*ShaCache) Get

func (c *ShaCache) Get(id git.Oid) (string, bool)

Get retrieves the corresponding SHA sum for the supplied Git object id.

type Upstream

type Upstream struct {
	URL *url.URL
}

Upstream represents an external registry.

func NewUpstream

func NewUpstream(rootURL string) (*Upstream, error)

NewUpstream instantiates a new registry proxy.

func (*Upstream) RedirectPackageRoot

func (u *Upstream) RedirectPackageRoot(name string, w http.ResponseWriter,
	req *http.Request)

RedirectPackageRoot redirects the client to the package root of the package with the specified name.

Jump to

Keyboard shortcuts

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