home: github.com/shurcooL/home/internal/code Index | Files | Directories

package code

import "github.com/shurcooL/home/internal/code"

Package code implements a Go code service backed by a repository store.


Package Files

code.go discover.go git.go module.go

func NewGitHandler Uses

func NewGitHandler(code *Service, reposDir, gitHooksDir string, events events.ExternalService, users users.Service, gitUsers map[string]users.User, authenticate func(*http.Request) *http.Request) (*gitHandler, error)

NewGitHandler creates a gitHandler. gitHooksDir specifies the directory where to look for git hooks.

func WriteModuleZip Uses

func WriteModuleZip(w io.Writer, m module.Version, r vcs.Repository, id vcs.CommitID) error

WriteModuleZip builds a zip archive for module version m by including all files from repository r at commit id, and writes the result to w.

WriteModuleZip does not support multi-module repositories. A go.mod file may be in root, but not in any other directory.

Unlike "golang.org/x/mod/zip".Create, it does not verify any module zip restrictions. It will produce an invalid module zip if given a commit containing invalid files. It should be used on commits that are known to have files that are all acceptable to include in a module zip.

type Directory Uses

type Directory struct {
    ImportPath   string
    RepoRoot     string // Empty string if directory is not in a repository.
    RepoPackages int    // Number of packages contained by repository (if any, otherwise 0).

    // LicenseRoot is the import path corresponding to this or nearest parent directory
    // that contains a LICENSE file, or empty string if there isn't such a directory.
    LicenseRoot string

    Package *Package

Directory represents a directory inside a repository store.

func (Directory) HasLicenseFile Uses

func (d Directory) HasLicenseFile() bool

HasLicenseFile reports whether directory d contains a LICENSE file.

func (Directory) IsRepoRoot Uses

func (d Directory) IsRepoRoot() bool

IsRepoRoot reports whether directory d corresponds to a repository root.

func (Directory) WithinRepo Uses

func (d Directory) WithinRepo() bool

WithinRepo reports whether directory d is contained by a repository.

type ModuleHandler Uses

type ModuleHandler struct {
    // Code is the underlying source of Go code.
    // Each repository root available in it is served as a Go module.
    Code *Service

ModuleHandler is a Go module server that implements the module proxy protocol, as specified at https://golang.org/cmd/go/#hdr-Module_proxy_protocol.

At this time, it has various restrictions compared to the general go mod download functionality that extracts module versions from a VCS repository:

• It serves only pseudo-versions derived from commits on master branch. No other versions or module queries are supported at this time.

• It serves a single module corresponding to the root of each repository. Multi-module repositories are not supported at this time.

• It serves only the v0 major version. Major versions other than v0 are not supported at this time.

This may change over time as my needs evolve.

func (ModuleHandler) ServeModule Uses

func (h ModuleHandler) ServeModule(w http.ResponseWriter, req *http.Request) error

ServeModule serves a module proxy protocol HTTP request.

The "$GOPROXY/" prefix must be stripped from req.URL.Path, so that the given req.URL.Path is like "<module>/@v/<version>.info" (no leading slash).

type Package Uses

type Package struct {
    Name     string
    Synopsis string // Package documentation synopsis.
    DocHTML  string // Package documentation HTML.

Package represents a Go package inside a repository store.

func (Package) IsCommand Uses

func (p Package) IsCommand() bool

IsCommand reports whether the package is a command.

type Service Uses

type Service struct {
    // contains filtered or unexported fields

Service is a Go code service implementation backed by a repository store.

func NewService Uses

func NewService(reposDir string, notification notification.Service, events events.ExternalService, users users.Service) (*Service, error)

NewService discovers Go code inside the repository store at reposDir, and returns a code service that uses said repository store.

func (*Service) CreateRepo Uses

func (s *Service) CreateRepo(ctx context.Context, repoSpec, description string) error

CreateRepo creates an empty repository with the specified repoSpec and description. If the directory already exists, os.ErrExist is returned.

func (*Service) GetDirectory Uses

func (s *Service) GetDirectory(_ context.Context, importPath string) (*Directory, error)

GetDirectory looks up a directory by specified import path. If the directory doesn't exist, os.ErrNotExist is returned.

func (*Service) ListDirectories Uses

func (s *Service) ListDirectories(context.Context) ([]*Directory, error)

ListDirectories lists directories in sorted order.

func (*Service) Rediscover Uses

func (s *Service) Rediscover(repoRoot string) (added, removed []*Directory, err error)

Rediscover rediscovers code in repoRoot of the repository store. It returns packages that have been added and removed.


httpclientPackage httpclient contains issues.Service implementation over HTTP.
httphandlerPackage httphandler contains an API handler for issues.Service.
httproutePackage httproute contains route paths for httpclient, httphandler.

Package code imports 40 packages (graph) and is imported by 5 packages. Updated 2020-07-08. Refresh now. Tools for package owners.