module

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2018 License: MIT Imports: 25 Imported by: 17

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearFiles added in v0.1.0

func ClearFiles(fs afero.Fs, root string) error

ClearFiles deletes all data from the given fs at path root This function must be called when zip is closed to cleanup the entire GOPATH created by the diskref

func Download

func Download(ctx context.Context, timeout time.Duration, baseURL, module, version string) (*storage.Version, error)

Download downloads the module/version from url. Returns a storage.Version representing the downloaded module/version or a non-nil error if something went wrong

func Dummy

func Dummy(fs afero.Fs, repoRoot string) error

Dummy Hacky thing makes vgo not to complain

func MakeZip

func MakeZip(fs afero.Fs, dir, module, version string) *io.PipeReader

MakeZip takes dir and module info and generates vgo valid zip the dir must end with a "/"

func NewErrModuleAlreadyFetched

func NewErrModuleAlreadyFetched(op errors.Op, mod, ver string) error

NewErrModuleAlreadyFetched returns an error indicating that a module has already been fetched

func NewErrModuleExcluded

func NewErrModuleExcluded(module string) error

NewErrModuleExcluded creates new ErrModuleExcluded

func PrepareEnv added in v0.1.0

func PrepareEnv(gopath string) []string

PrepareEnv will return all the appropriate environment variables for a Go Command to run successfully (such as GOPATH, GOCACHE, PATH etc)

Types

type Downloader

type Downloader func(ctx context.Context, timeout time.Duration, baseURL, module, version string) (*storage.Version, error)

Downloader downloads a module version from a URL exposing Download Protocol endpoints

type ErrModuleExcluded

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

ErrModuleExcluded is error returned when processing of error is skipped due to filtering rules

func (*ErrModuleExcluded) Error

func (e *ErrModuleExcluded) Error() string

type Fetcher

type Fetcher interface {
	// Fetch fetches the module and puts it somewhere addressable by ModuleRef.
	// returns a non-nil error on failure.
	//
	// The caller should call moduleRef.Clear() after they're done with the module
	Fetch(mod, ver string) (Ref, error)
}

Fetcher fetches module from an upstream source

Example
repoURI := "github.com/arschles/assert"
version := "v1.0.0"
goBinaryName := env.GoBinPath()
fetcher, err := NewGoGetFetcher(goBinaryName, afero.NewOsFs())
if err != nil {
	log.Fatal(err)
}
ref, err := fetcher.Fetch(repoURI, version)
// handle errors if any
if err != nil {
	return
}
versionData, err := ref.Read()
// Close the handle to versionData.Zip once done
// This will also handle cleanup so it's important to call Close
defer versionData.Zip.Close()
if err != nil {
	return
}
// Do something with versionData
fmt.Println(string(versionData.Mod))
Output:

module github.com/arschles/assert

func NewGoGetFetcher

func NewGoGetFetcher(goBinaryName string, fs afero.Fs) (Fetcher, error)

NewGoGetFetcher creates fetcher which uses go get tool to fetch modules

type Filter

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

Filter is a filter of modules

func NewFilter

func NewFilter() *Filter

NewFilter creates new filter based on rules defined in a configuration file WARNING: this is not concurrently safe Configuration consists of two operations: + for include and - for exclude e.g.

  • github.com/a
  • github.com/a/b

will communicate all modules except github.com/a and its children, but github.com/a/b will be communicated example 2:

-
+ github.com/a

will exclude all items from communication except github.com/a

func (*Filter) AddRule

func (f *Filter) AddRule(path string, rule FilterRule)

AddRule adds rule for specified path

func (*Filter) Rule added in v0.1.0

func (f *Filter) Rule(path string) FilterRule

Rule returns the filter rule to be applied to the given path

type FilterRule

type FilterRule int

FilterRule defines behavior of module communication

const (
	// Default filter rule does not alter default behavior
	Default FilterRule = iota
	// Include filter rule includes package and its children from communication
	Include
	// Exclude filter rule excludes package and its children from communication
	Exclude
	// Direct filter rule forces the package to be fetched directly from the vcs
	Direct
)

type Ref

type Ref interface {
	// Read reads the module into memory and returns it. Notice that the Zip field on the returned
	// storage.Version is an io.ReadCloser, so make sure to call Close on it after you're done
	// with it.
	Read() (*storage.Version, error)
}

Ref points to a module somewhere

Jump to

Keyboard shortcuts

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