proxy

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package proxy implements the HTTP protocols for serving a Go module proxy.

Index

Constants

View Source
const ListExpire = 5 * time.Minute

Variables

This section is empty.

Functions

func GlobsMatchPath

func GlobsMatchPath(globs, target string) bool

GlobsMatchPath reports whether any path prefix of target matches one of the glob patterns (as defined by path.Match) in the comma-separated globs list. It ignores any empty or malformed patterns in the list.

Types

type File

type File interface {
	io.Reader
	io.Seeker
	io.Closer
	Stat() (os.FileInfo, error)
}

A File is a file to be served, typically an *os.File or the result of calling MemFile or NewInfo. The modification time is the only necessary field in the Stat result.

func MemFile

func MemFile(data []byte, t time.Time) File

MemFile returns an File containing the given in-memory content and modification time.

func NewInfo

func NewInfo(version string, t time.Time) File

NewInfo returns a formatted info file for the given version, time pair. The version should be a canonical semantic version.

type Router

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

A Router is the proxy HTTP server, which implements Route Filter to routing private module or public module .

func NewRouter

func NewRouter(server *Server, proxyUrl, pattern, downRoot string) *Router

NewRouter returns a new Router using the given operations.

func (*Router) Direct

func (rt *Router) Direct(path string) bool

func (*Router) ServeHTTP

func (rt *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Server

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

A Server is the proxy HTTP server, which implements http.Handler and should be invoked to serve the paths listed in ServerPaths.

The server assumes that the requests are made to the root of the URL space, so it should typically be registered using:

server := proxy.NewServer(ops)
http.Handle("/", server)

To register a server at a subdirectory of the URL space, wrap the server in http.StripPrefix:

server := proxy.NewServer(ops)
http.Handle("/proxy/", http.StripPrefix("/proxy", server))

All recognized requests to the server contain the substring "/@v/" in the URL. The server will respond with an http.StatusBadRequest (400) error to unrecognized requests.

func NewServer

func NewServer(ops ServerOps) *Server

NewServer returns a new Server using the given operations.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is the server's implementation of http.Handler.

type ServerOps

type ServerOps interface {
	// NewContext returns the context to use for the request r.
	NewContext(r *http.Request) (context.Context, error)
	// List, Latest, Info, GoMod, and Zip all return a File to be sent to a client.
	// The File will be closed after its contents are sent.
	// In the case of an error, if the error satisfies errors.Is(err, os.ErrNotFound),
	// the server responds with an HTTP 404 error;
	// otherwise it responds with an HTTP 500 error.
	// List returns a list of tagged versions of the module identified by path.
	// The versions should all be canonical semantic versions
	// and formatted in a text listing, one per line.
	// Pseudo-versions derived from untagged commits should be omitted.
	// The go command exposes this list in 'go list -m -versions' output
	// and also uses it to resolve wildcards like 'go get m@v1.2'.
	List(ctx context.Context, path string) (File, error)
	// Latest returns an info file for the latest known version of the module identified by path.
	// The go command uses this for 'go get m' or 'go get m@latest'
	// but only after finding no suitable version among the ones returned by List.
	// Typically, Latest should return a pseudo-version for the latest known commit.
	Latest(ctx context.Context, path string) (File, error)
	// Info opens and returns the module version's info file.
	// The requested version can be a canonical semantic version
	// but can also be an arbitrary version reference, like "master".
	//
	// The metadata in the returned file should be a JSON object corresponding
	// to the Go type
	//
	//	type Info struct {
	//		Version string
	//		Time time.Time
	//	}
	//
	// where the version is the resolved canonical semantic version
	// and the time is the commit or publication time of that version
	// (for use with go list -m).
	// The NewInfo function can be used to construct an info File.
	//
	// Proxies should obtain the module version information by
	// executing 'go mod download -json' and caching the file
	// listed in the Info field.
	Info(ctx context.Context, m module.Version) (File, error)
	// GoMod opens and returns the module's go.mod file.
	// The requested version is a canonical semantic version.
	//
	// Proxies should obtain the module version information by
	// executing 'go mod download -json' and caching the file
	// listed in the GoMod field.
	GoMod(ctx context.Context, m module.Version) (File, error)
	// Zip opens and returns the module's zip file.
	// The requested version is a canonical semantic version.
	//
	// Proxies should obtain the module version information by
	// executing 'go mod download -json' and caching the file
	// listed in the Zip field.
	Zip(ctx context.Context, m module.Version) (File, error)
}

A ServerOps provides the external operations (accessing module information and so on) needed by the Server.

Jump to

Keyboard shortcuts

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