go: github.com/golang/go/src/cmd/go/internal/sumweb Index | Files

package sumweb

import "github.com/golang/go/src/cmd/go/internal/sumweb"

Package sumweb implements the HTTP protocols for serving or accessing a go.sum database.


Package Files

cache.go client.go encode.go server.go test.go


var ErrGONOSUMDB = errors.New("skipped (listed in GONOSUMDB)")

ErrGONOSUMDB is returned by Lookup for paths that match a pattern listed in the GONOSUMDB list (set by SetGONOSUMDB, usually from the environment variable).

var ErrSecurity = errors.New("security error: misbehaving server")

ErrSecurity is returned by Conn operations that invoke Client.SecurityError.

var ErrWriteConflict = errors.New("write conflict")

ErrWriteConflict signals a write conflict during Client.WriteConfig.

var Paths = []string{

Paths are the URL paths for which Handler should be invoked.

Typically a server will do:

handler := &sumweb.Handler{Server: srv}
for _, path := range sumweb.Paths {
	http.HandleFunc(path, handler)

type Client Uses

type Client interface {
    // ReadRemote reads and returns the content served at the given path
    // on the remote database server. The path begins with "/lookup" or "/tile/".
    // It is the implementation's responsibility to turn that path into a full URL
    // and make the HTTP request. ReadRemote should return an error for
    // any non-200 HTTP response status.
    ReadRemote(path string) ([]byte, error)

    // ReadConfig reads and returns the content of the named configuration file.
    // There are only a fixed set of configuration files.
    // "key" returns a file containing the verifier key for the server.
    // serverName + "/latest" returns a file containing the latest known
    // signed tree from the server. It is read and written (using WriteConfig).
    // To signal that the client wishes to start with an "empty" signed tree,
    // ReadConfig can return a successful empty result (0 bytes of data).
    ReadConfig(file string) ([]byte, error)

    // WriteConfig updates the content of the named configuration file,
    // changing it from the old []byte to the new []byte.
    // If the old []byte does not match the stored configuration,
    // WriteConfig must return ErrWriteConflict.
    // Otherwise, WriteConfig should atomically replace old with new.
    WriteConfig(file string, old, new []byte) error

    // ReadCache reads and returns the content of the named cache file.
    // Any returned error will be treated as equivalent to the file not existing.
    // There can be arbitrarily many cache files, such as:
    //	serverName/lookup/pkg@version
    //	serverName/tile/8/1/x123/456
    ReadCache(file string) ([]byte, error)

    // WriteCache writes the named cache file.
    WriteCache(file string, data []byte)

    // Log prints the given log message (such as with log.Print)
    Log(msg string)

    // SecurityError prints the given security error log message.
    // The Conn returns ErrSecurity from any operation that invokes SecurityError,
    // but the return value is mainly for testing. In a real program,
    // SecurityError should typically print the message and call log.Fatal or os.Exit.
    SecurityError(msg string)

A Client provides the external operations (file caching, HTTP fetches, and so on) needed to implement the HTTP client Conn. The methods must be safe for concurrent use by multiple goroutines.

type Conn Uses

type Conn struct {
    // contains filtered or unexported fields

A Conn is a client connection to a go.sum database. All the methods are safe for simultaneous use by multiple goroutines.

func NewConn Uses

func NewConn(client Client) *Conn

NewConn returns a new Conn using the given Client.

func (*Conn) Lookup Uses

func (c *Conn) Lookup(path, vers string) (lines []string, err error)

Lookup returns the go.sum lines for the given module path and version. The version may end in a /go.mod suffix, in which case Lookup returns the go.sum lines for the module's go.mod-only hash.

func (*Conn) SetGONOSUMDB Uses

func (c *Conn) SetGONOSUMDB(list string)

SetGONOSUMDB sets the list of comma-separated GONOSUMDB patterns for the Conn. For any module path matching one of the patterns, Lookup will return ErrGONOSUMDB. Any call to SetGONOSUMDB must happen before the first call to Lookup.

func (*Conn) SetTileHeight Uses

func (c *Conn) SetTileHeight(height int)

SetTileHeight sets the tile height for the Conn. Any call to SetTileHeight must happen before the first call to Lookup. If SetTileHeight is not called, the Conn defaults to tile height 8.

type Handler Uses

type Handler struct {
    Server Server

A Handler is the go.sum database server handler, which should be invoked to serve the paths listed in Paths. The calling code is responsible for initializing Server.

func (*Handler) ServeHTTP Uses

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Server Uses

type Server interface {
    // NewContext returns the context to use for the request r.
    NewContext(r *http.Request) (context.Context, error)

    // Signed returns the signed hash of the latest tree.
    Signed(ctx context.Context) ([]byte, error)

    // ReadRecords returns the content for the n records id through id+n-1.
    ReadRecords(ctx context.Context, id, n int64) ([][]byte, error)

    // Lookup looks up a record by its associated key ("module@version"),
    // returning the record ID.
    Lookup(ctx context.Context, key string) (int64, error)

    // ReadTileData reads the content of tile t.
    // It is only invoked for hash tiles (t.L ≥ 0).
    ReadTileData(ctx context.Context, t tlog.Tile) ([]byte, error)

A Server provides the external operations (underlying database access and so on) needed to implement the HTTP server Handler.

type TestServer Uses

type TestServer struct {
    // contains filtered or unexported fields

A TestServer is an in-memory implementation of Server for testing.

func NewTestServer Uses

func NewTestServer(signer string, gosum func(path, vers string) ([]byte, error)) *TestServer

NewTestServer constructs a new TestServer that will sign its tree with the given signer key (see cmd/go/internal/note) and fetch new records as needed by calling gosum.

func (*TestServer) Lookup Uses

func (s *TestServer) Lookup(ctx context.Context, key string) (int64, error)

func (*TestServer) NewContext Uses

func (s *TestServer) NewContext(r *http.Request) (context.Context, error)

func (*TestServer) ReadRecords Uses

func (s *TestServer) ReadRecords(ctx context.Context, id, n int64) ([][]byte, error)

func (*TestServer) ReadTileData Uses

func (s *TestServer) ReadTileData(ctx context.Context, t tlog.Tile) ([]byte, error)

func (*TestServer) Signed Uses

func (s *TestServer) Signed(ctx context.Context) ([]byte, error)

Package sumweb imports 14 packages (graph). Updated 2019-06-20. Refresh now. Tools for package owners.

The go get command cannot install this package because of the following issues: