cache

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package cache handles managing the actual installing of tools. It handles downloading and building the go modules. Tools are stored in a cache on the OS filesystem so that they can be reused by other projects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoVersion

func GoVersion(ctx context.Context) (string, error)

GoVersion finds the version of Go that is installed.

Types

type Cache

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

Cache manages tools in an OS filesystem directory.

func New

func New(dir string, opts ...Option) *Cache

New creates a new Cache instance that uses the directory dir. Options can be provided to customize the Cache instance.

func (*Cache) Clean

func (c *Cache) Clean() error

Clean removes the cache directory and all contents from the filesystem.

func (*Cache) Dir

func (c *Cache) Dir() string

Dir returns the OS filesystem directory used by this Cache.

func (*Cache) FindUpdate

func (c *Cache) FindUpdate(ctx context.Context, t tool.Tool) (string, error)

FindUpdate checks if there is a newer version available for tool t. If no newer version is found, an empty string is returned.

func (*Cache) Install

func (c *Cache) Install(ctx context.Context, t tool.Tool) (tool.Tool, error)

Install installs the given tool. t must have ImportPath set, otherwise an error will be returned. If t.Version is empty, then the latest version of the tool will be installed. The returned tool will have Version set to the version that was installed.

The provided context is used to terminate the install if the context becomes done before the install completes on its own.

func (*Cache) ToolPath

func (c *Cache) ToolPath(t tool.Tool) (string, error)

ToolPath returns the absolute path the the installed binary for the given tool. If the binary cannot be found, an error is returned.

type Go

type Go interface {
	// Build builds pkg and outputs the binary at outPath. dir is used as the working directory
	// when building. pkg must be a valid import path.
	// Build functions like 'go build -o'.
	//
	// The provided context is used to terminate the build if the context becomes
	// done before the build completes on its own.
	Build(ctx context.Context, pkg, outPath, dir string) error
	// GetD downloads the source code for the module mod. dir is used as the working directory
	// and is expected to contain a go.mod file which will be updated with the installed module.
	// mod must be a valid module name, that is an import path, optionally with a version.
	// If no version is provided, the latest version will be downloaded.
	// GetD functions like 'got get -d' in module aware mode.
	//
	// The provided context is used to terminate the download if the context becomes
	// done before the download completes on its own.
	GetD(ctx context.Context, mod, dir string) error
	// ListU lists the details of mod and a version update if one is available. dir is used as
	// the working directory and is expected to contain a go.mod file with mod.
	// ListU functions like 'go list -m -u -json'.
	//
	// The provided context is used to terminate listing if the context becomes done
	// before listing completes on its own.
	ListU(ctx context.Context, mod, dir string) (GoModule, error)
}

Go represents the core functionality provided by the go command. It allows for downloading and building of modules.

func NewGo

func NewGo() Go

NewGo returns a new Go instance which allows for downloading and building modules.

func NewMockGo

func NewMockGo(tools map[string]map[string]string) (Go, error)

NewMockGo returns a new Go instance that is suitable for testing. Tools is a map of import paths to a map of queries to versions.

type GoModule

type GoModule struct {
	Path    string    // module path
	Version string    // module version
	Update  *GoModule // available update, if any (with -u)
}

type Option

type Option func(*Cache)

Option is a function that takes a Cache instance and applies a configuration to it.

func WithGo

func WithGo(goClient Go) Option

WithGo sets the Go client that should be used to download and build tools.

func WithLogger

func WithLogger(logger logrus.FieldLogger) Option

WithLogger sets a logger that should be used for writing debug messages. By default no logging is done.

Jump to

Keyboard shortcuts

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