vcweb

package standard library
go1.22.10 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: BSD-3-Clause Imports: 31 Imported by: 0

Documentation

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ScriptNotFoundError

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

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

func (ScriptNotFoundError) Error

func (e ScriptNotFoundError) Error() string

func (ScriptNotFoundError) Unwrap

func (e ScriptNotFoundError) Unwrap() error

type Server

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

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

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

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

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

func (ServerNotInstalledError) Error

func (v ServerNotInstalledError) Error() string

Directories

Path Synopsis
Package vcstest serves the repository scripts in cmd/go/testdata/vcstest using the vcweb script engine.
Package vcstest serves the repository scripts in cmd/go/testdata/vcstest using the vcweb script engine.

Jump to

Keyboard shortcuts

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