gosrc

package
v0.0.0-...-3cfd0ea Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: BSD-3-Clause, BSD-3-Clause Imports: 25 Imported by: 0

README

Package gosrc fetches Go package source code from version control services.

Contributions

Contributions to this project are welcome, though please send mail before starting work on anything major. Contributors retain their copyright, so we need you to fill out a short form before we can accept your contribution: https://developers.google.com/open-source/cla/individual

Documentation

Overview

Package gosrc fetches Go package source code from version control services.

Index

Constants

View Source
const ExpiresAfter = 2 * 365 * 24 * time.Hour // Package with no commits and imports expires.

Variables

View Source
var TempDir = filepath.Join(os.TempDir(), "gddo")

Store temporary data in this directory.

Functions

func GetGitHubUpdates

func GetGitHubUpdates(ctx context.Context, client *http.Client, pushedAfter string) (maxPushedAt string, names []string, err error)

GetGitHubUpdates returns the full names ("owner/repo") of recently pushed GitHub repositories. by pushedAfter.

func IsGoRepoPath

func IsGoRepoPath(path string) bool

IsGoRepoPath returns true if path is in $GOROOT/src.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if err is of type NotFoundError.

func IsValidPath

func IsValidPath(importPath string) bool

IsValidPath returns true if importPath is structurally valid.

func IsValidRemotePath

func IsValidRemotePath(importPath string) bool

IsValidRemotePath returns true if importPath is structurally valid for "go get".

func MaybeRedirect

func MaybeRedirect(importPath, importComment, resolvedGitHubPath string) error

MaybeRedirect uses the provided import path, import comment, and resolved GitHub path to make a decision of whether to redirect to another, more canonical import path. It returns nil error to indicate no redirect, or a NotFoundError error to redirect.

func OverwriteLineComments

func OverwriteLineComments(p []byte)

func SetLocalDevMode

func SetLocalDevMode(path string)

SetLocalDevMode sets the package to local development mode. In this mode, the GOPATH specified by path is used to find directories instead of version control services.

Types

type Directory

type Directory struct {
	// The import path for this package.
	ImportPath string

	// Import path of package after resolving go-import meta tags, if any.
	ResolvedPath string

	// Import path of package with the canonical user/repo case as reported by
	// the github.com server. Optional.
	// If set, used to ensure canonical case is used when there's no import path
	// comment (e.g., to redirect from "github.com/UsEr/rEpO/dir" to
	// "github.com/User/Repo/dir").
	ResolvedGitHubPath string

	// Import path prefix for all packages in the project.
	ProjectRoot string

	// Name of the project.
	ProjectName string

	// Project home page.
	ProjectURL string

	// Version control system: git, hg, bzr, ...
	VCS string

	// Version control: active or should be suppressed.
	Status DirectoryStatus

	// Cache validation tag. This tag is not necessarily an HTTP entity tag.
	// The tag is "" if there is no meaningful cache validation for the VCS.
	Etag string

	// Files.
	Files []*File

	// Subdirectories, not guaranteed to contain Go code.
	Subdirectories []string

	// Location of directory on version control service website.
	BrowseURL string

	// Format specifier for link to source line. It must contain one %s (file URL)
	// followed by one %d (source line number), or be empty string if not available.
	// Example: "%s#L%d".
	LineFmt string

	// Whether the repository of this directory is a fork of another one.
	Fork bool

	// How many stars (for a GitHub project) the repository of this directory has.
	Stars int
}

Directory describes a directory on a version control service.

func Get

func Get(ctx context.Context, client *http.Client, importPath string, etag string) (dir *Directory, err error)

func (*Directory) Import

func (dir *Directory) Import(ctx *build.Context, mode build.ImportMode) (*build.Package, error)

Import returns details about the package in the directory.

type DirectoryStatus

type DirectoryStatus int
const (
	Active          DirectoryStatus = iota
	DeadEndFork                     // Forks with no commits
	QuickFork                       // Forks with less than 3 commits, all within a week from creation
	NoRecentCommits                 // No commits for ExpiresAfter

	// No commits for ExpiresAfter and no imports.
	// This is a status derived from NoRecentCommits and the imports count information in the db.
	Inactive
)

type File

type File struct {
	// File name with no directory.
	Name string

	// Contents of the file.
	Data []byte

	// Location of file on version control service website.
	BrowseURL string
}

File represents a file.

type NotFoundError

type NotFoundError struct {
	// Diagnostic message describing why the directory was not found.
	Message string

	// Redirect specifies the path where package can be found.
	Redirect string
}

NotFoundError indicates that the directory or presentation was not found.

func (NotFoundError) Error

func (e NotFoundError) Error() string

type NotModifiedError

type NotModifiedError struct {
	Since  time.Time
	Status DirectoryStatus
}

func (NotModifiedError) Error

func (e NotModifiedError) Error() string

type Presentation

type Presentation struct {
	Filename string
	Files    map[string][]byte
	Updated  time.Time
}

func GetPresentation

func GetPresentation(ctx context.Context, client *http.Client, importPath string) (*Presentation, error)

GetPresentation gets a presentation from the the given path.

type Project

type Project struct {
	Description string
}

Project represents a repository.

func GetProject

func GetProject(ctx context.Context, client *http.Client, importPath string) (*Project, error)

GetProject gets information about a repository.

type RemoteError

type RemoteError struct {
	Host string
	// contains filtered or unexported fields
}

func (*RemoteError) Error

func (e *RemoteError) Error() string

Jump to

Keyboard shortcuts

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