...

Package vcweb

import "cmd/go/internal/vcweb"
Overview
Index
Subdirectories

Overview ▾

Package vcweb serves version control repos for testing the go command.

It is loosely derived from golang.org/x/build/vcs-test/vcweb, which ran as a service hosted at vcs-test.golang.org.

When a repository URL is first requested, the vcweb Server dynamically regenerates the repository using a script interpreted by a script.Engine. The script produces the server's contents for a corresponding root URL and all subdirectories of that URL, which are then cached: subsequent requests for any URL generated by the script will serve the script's previous output until the script is modified.

The script engine includes all of the engine's default commands and conditions, as well as commands for each supported VCS binary (bzr, fossil, git, hg, and svn), a "handle" command that informs the script which protocol or handler to use to serve the request, and utilities "at" (which sets environment variables for Git timestamps) and "unquote" (which unquotes its argument as if it were a Go string literal).

The server's "/" endpoint provides a summary of the available scripts, and "/help" provides documentation for the script environment.

To run a standalone server based on the vcweb engine, use:

go test cmd/go/internal/vcweb/vcstest -v --port=0

type ScriptNotFoundError

A ScriptNotFoundError indicates that the requested script file does not exist. (It typically wraps a "stat" error for the script file.)

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

func (ScriptNotFoundError) Error

func (e ScriptNotFoundError) Error() string

func (ScriptNotFoundError) Unwrap

func (e ScriptNotFoundError) Unwrap() error

type Server

A Server serves cached, dynamically-generated version control repositories.

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

func NewServer

func NewServer(scriptDir, workDir string, logger *log.Logger) (*Server, error)

NewServer returns a Server that generates and serves repositories in workDir using the scripts found in scriptDir and its subdirectories.

A request for the path /foo/bar/baz will be handled by the first script along that path that exists: $scriptDir/foo.txt, $scriptDir/foo/bar.txt, or $scriptDir/foo/bar/baz.txt.

func (*Server) Close

func (s *Server) Close() error

func (*Server) HandleScript

func (s *Server) HandleScript(scriptRelPath string, logger *log.Logger, f func(http.Handler)) error

HandleScript ensures that the script at scriptRelPath has been evaluated with its current contents.

If the script completed successfully, HandleScript invokes f on the handler with the script's result still read-locked, and waits for it to return. (That ensures that cache invalidation does not race with an in-flight handler.)

Otherwise, HandleScript returns the (cached) error from executing the script.

func (*Server) ServeHTTP

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

ServeHTTP implements http.Handler for version-control repositories.

type ServerNotInstalledError

A ServerNotInstalledError indicates that the server binary required for the indicated VCS does not exist.

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

func (ServerNotInstalledError) Error

func (v ServerNotInstalledError) Error() string

Subdirectories

Name Synopsis
..