goproxy: Index | Files | Directories

package goproxy

import ""

Package goproxy implements a minimalist Go module proxy handler.


Package Files

cacher.go goproxy.go mod.go response.go


var ErrCacheNotFound = errors.New("cache not found")

ErrCacheNotFound is the error resulting if a path search failed to find a cache.

type Cache Uses

type Cache interface {

    // Name returns the unique Unix path style name of the underlying cache.
    Name() string

    // Size returns the length in bytes of the underlying cache.
    Size() int64

    // ModTime returns the modification time of the underlying cache.
    ModTime() time.Time

    // Checksum returns the checksum of the underlying cache.
    Checksum() []byte

Cache is the cache unit of the `Cacher`.

type Cacher Uses

type Cacher interface {
    // NewHash returns a new instance of the `hash.Hash` used to compute the
    // checksums of the caches in the underlying cacher.
    NewHash() hash.Hash

    // Cache returns the matched `Cache` for the name from the underlying
    // cacher. It returns the `ErrCacheNotFound` if not found.
    // It is the caller's responsibility to close the returned `Cache`.
    Cache(ctx context.Context, name string) (Cache, error)

    // SetCache sets the c to the underlying cacher.
    // It is the caller's responsibility to close the c.
    SetCache(ctx context.Context, c Cache) error

Cacher is the interface that defines a set of methods used to cache module files for the `Goproxy`.

If you are looking for some useful implementations of the `Cacher`, simply visit the "" package.

type Goproxy Uses

type Goproxy struct {
    // GoBinName is the name of the Go binary.
    // Default: "go"
    GoBinName string `mapstructure:"go_bin_name"`

    // MaxGoBinWorkers is the maximum number of the Go binary commands that
    // are allowed to execute at the same time.
    // Default: 8
    MaxGoBinWorkers int `mapstructure:"max_go_bin_workers"`

    // PathPrefix is the prefix of all request paths. It will be used to
    // trim the request paths via `strings.TrimPrefix`.
    // Note that when the `PathPrefix` is not empty, then it should start
    // with "/".
    // Default: ""
    PathPrefix string `mapstructure:"path_prefix"`

    // Cacher is the `Cacher` that used to cache module files.
    // If the `Cacher` is nil, the module files will be temporarily stored
    // in runtime memory and discarded as the request ends.
    // Default: nil
    Cacher Cacher `mapstructure:"cacher"`

    // SupportedSUMDBHosts is the supported checksum database hosts.
    // Default: [""]
    SupportedSUMDBHosts []string `mapstructure:"supported_sumdb_hosts"`

    // ErrorLogger is the `log.Logger` that logs errors that occur while
    // proxing.
    // If the `ErrorLogger` is nil, logging is done via the log package's
    // standard logger.
    // Default: nil
    ErrorLogger *log.Logger `mapstructure:"-"`
    // contains filtered or unexported fields

Goproxy is the top-level struct of this project.

Note that the `Goproxy` will not mess with your environment variables, it will still follow your GOPROXY, GONOPROXY, GOSUMDB, and GONOSUMDB. This means that you can set GOPROXY to serve the `Goproxy` itself under other proxies, and by setting GONOPROXY to indicate which modules the `Goproxy` should download directly instead of using GOPROXY. And of course, you can also set GOSUMDB and GONOSUMDB to indicate how the `Goproxy` should verify the modules.

ATTENTION: Since GONOPROXY has not yet been released (it will be introduced in Go 1.13), so we implemented a built-in GONOPROXY support for the `Goproxy`. Now, you can set GONOPROXY even before Go 1.13.

It is highly recommended not to modify the value of any field of the `Goproxy` after calling the `Goproxy.ServeHTTP`, which will cause unpredictable problems.

The new instances of the `Goproxy` should only be created by calling the `New`.

func New Uses

func New() *Goproxy

New returns a new instance of the `Goproxy` with default field values.

The `New` is the only function that creates new instances of the `Goproxy` and keeps everything working.

func (*Goproxy) ServeHTTP Uses

func (g *Goproxy) ServeHTTP(rw http.ResponseWriter, r *http.Request)

ServeHTTP implements `http.Handler`.



Package goproxy imports 22 packages (graph) and is imported by 2 packages. Updated 2019-07-18. Refresh now. Tools for package owners.