download

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package download provides http handlers that implement vgo's Download Protocol.

Index

Constants

View Source
const (
	Strict   = "strict"
	Offline  = "offline"
	Fallback = "fallback"
)

NetworkMode constants.

View Source
const PathLatest = "/{module:.+}/@latest"

PathLatest URL.

View Source
const PathList = "/{module:.+}/@v/list"

PathList URL.

View Source
const PathVersionInfo = "/{module:.+}/@v/{version}.info"

PathVersionInfo URL.

View Source
const PathVersionModule = "/{module:.+}/@v/{version}.mod"

PathVersionModule URL.

View Source
const PathVersionZip = "/{module:.+}/@v/{version}.zip"

PathVersionZip URL.

Variables

This section is empty.

Functions

func InfoHandler added in v0.8.1

func InfoHandler(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Handler

InfoHandler implements GET baseURL/module/@v/version.info.

func LatestHandler

func LatestHandler(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Handler

LatestHandler implements GET baseURL/module/@latest.

func ListHandler

func ListHandler(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Handler

ListHandler implements GET baseURL/module/@v/list.

func LogEntryHandler added in v0.8.1

func LogEntryHandler(ph ProtocolHandler, opts *HandlerOpts) http.Handler

LogEntryHandler pulls a log entry from the request context. Thanks to the LogEntryMiddleware, we should have a log entry stored in the context for each request with request-specific fields. This will grab the entry and pass it to the protocol handlers.

func ModuleHandler added in v0.8.1

func ModuleHandler(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Handler

ModuleHandler implements GET baseURL/module/@v/version.mod.

func RegisterHandlers added in v0.8.1

func RegisterHandlers(r *mux.Router, opts *HandlerOpts)

RegisterHandlers is a convenience method that registers all the download protocol paths for you.

func ZipHandler added in v0.8.1

func ZipHandler(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Handler

ZipHandler implements GET baseURL/module/@v/version.zip.

Types

type HandlerOpts added in v0.8.1

type HandlerOpts struct {
	Protocol     Protocol
	Logger       *log.Logger
	DownloadFile *mode.DownloadFile
}

HandlerOpts are the generic options for a ProtocolHandler.

type Opts added in v0.8.1

type Opts struct {
	Storage      storage.Backend
	Stasher      stash.Stasher
	Lister       module.UpstreamLister
	DownloadFile *mode.DownloadFile
	NetworkMode  string
}

Opts specifies download protocol options to avoid long func signature.

type Protocol

type Protocol interface {
	// List implements GET /{module}/@v/list
	List(ctx context.Context, mod string) ([]string, error)

	// Info implements GET /{module}/@v/{version}.info
	Info(ctx context.Context, mod, ver string) ([]byte, error)

	// Latest implements GET /{module}/@latest
	Latest(ctx context.Context, mod string) (*storage.RevInfo, error)

	// GoMod implements GET /{module}/@v/{version}.mod
	GoMod(ctx context.Context, mod, ver string) ([]byte, error)

	// Zip implements GET /{module}/@v/{version}.zip
	Zip(ctx context.Context, mod, ver string) (storage.SizeReadCloser, error)
}

Protocol is the download protocol which mirrors the http requests that cmd/go makes to the proxy.

func New

func New(opts *Opts, wrappers ...Wrapper) Protocol

New returns a full implementation of the download.Protocol that the proxy needs. New also takes a variadic list of wrappers to extend the protocol's functionality (see addons package). The wrappers are applied in order, meaning the last wrapper passed is the Protocol that gets hit first.

type ProtocolHandler added in v0.8.1

type ProtocolHandler func(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Handler

ProtocolHandler is a function that takes all that it needs to return a ready-to-go http handler that serves up cmd/go's download protocol.

type Wrapper added in v0.8.1

type Wrapper func(Protocol) Protocol

Wrapper helps extend the main protocol's functionality with addons.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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