Documentation ¶
Overview ¶
Copyright 2019 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. Package proxy implements the HTTP protocols for serving a Go module proxy.
Index ¶
Constants ¶
Variables ¶
This section is empty.
Functions ¶
Types ¶
type File ¶
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 ¶
MemFile returns an File containing the given in-memory content and modification time.
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(srv *Server, opts *RouterOptions) *Router
NewRouter returns a new Router using the given operations.
type RouterOptions ¶
A RouterOps provides the proxy host and the external pattern
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:
srv := proxy.NewServer(ops) http.Handle("/", srv)
To register a server at a subdirectory of the URL space, wrap the server in http.StripPrefix:
srv := proxy.NewServer(ops) http.Handle("/proxy/", http.StripPrefix("/proxy", srv))
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 ¶
NewServer returns a new Server using the given operations.
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.