pkg

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2018 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CONTEXT_OS       = "Os"
	CONTEXT_ARCH     = "Arch"
	CONTEXT_VERSION  = "Version"
	CONTEXT_NAME     = "Name"
	CONTEXT_FULLNAME = "FullName"
)

Predefined context keys.

Variables

View Source
var ErrMiss = errors.New("cache missed")

ErrMiss is returned when the cache is accessed when it's empty.

Functions

func MustConstraint

func MustConstraint(c string) *semver.Constraints

MustConstraint creates a new constraint and panics on error.

Types

type Binary

type Binary struct {
	// Name of the binary
	Name string

	// Full name of the binary (as in the binary URL)
	FullName string

	// Homepage of the binary (if any)
	Homepage string

	// Simple description about what this software does
	Description string

	// Binary version
	Version *semver.Version

	// Download URL
	URL string

	// Effective file name (when extracting from an archive)
	//
	// Falls back to binary name when not provided.
	File string
}

Binary represents information for a specific version.

type BinaryTemplate

type BinaryTemplate struct {
	// Overrides the automatically calculated name based on the full name of the binary
	Name string

	// Homepage of the binary (if any)
	Homepage string

	// Simple description about what this software does
	Description string

	// Download URL
	URL *template.Template

	// Effective file name (when extracting from an archive)
	//
	// Falls back to binary name when not provided.
	File *template.Template
}

BinaryTemplate represents information used for creating an actual binary instance.

func (*BinaryTemplate) Resolve

func (t *BinaryTemplate) Resolve(fullName string, version *semver.Version, ctx map[string]string) (*Binary, error)

type Cache

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

func NewCache

func NewCache() *Cache

NewCache returns a new cache instance.

func (*Cache) File

func (c *Cache) File(binary *Binary) string

File returns the cached file path for a binary.

func (*Cache) GetFile

func (c *Cache) GetFile(binary *Binary) (*os.File, error)

GetFile returns the binary file.

Returns ErrMiss when accessing the cache when it's empty.

func (*Cache) Hit

func (c *Cache) Hit(binary *Binary) bool

Hit checks whether the binary can be found in the cache.

func (*Cache) Miss

func (c *Cache) Miss(binary *Binary) bool

Miss checks whether a binary cannot be found in the cache.

func (*Cache) Path

func (c *Cache) Path(binary *Binary) string

Path returns the cache path for a binary.

func (*Cache) Prepare

func (c *Cache) Prepare(binary *Binary) error

Prepare prepares the cache directory for a binary.

type Downloader

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

func NewDownloader

func NewDownloader(cache *Cache, logger logrus.FieldLogger) *Downloader

NewDownloader returns a new Downloader instance.

func (*Downloader) Download

func (d *Downloader) Download(binary *Binary, dst string) error

Download downloads a file if necessary (not found in cache) and copies it to the target directory.

type Provider

type Provider interface {
	Find(fullName string, version string) (*Binary, error)
}

Provider returns a binary.

type Resolver

type Resolver struct {
	Providers map[string]Provider
}

Resolver is responsible for resolving a binary URL into an actual binary.

func (*Resolver) Resolve

func (r *Resolver) Resolve(binaryUrl string) (*Binary, error)

Resolve resolves a binary URL into an actual binary.

type Rule

type Rule struct {
	Constraint *semver.Constraints
	Template   *BinaryTemplate
}

Rule binds a template and it's version condition together.

type RuleSet

type RuleSet map[string][]*Rule

RuleSet contains the whole set of builtin rules.

func (RuleSet) Resolve

func (r RuleSet) Resolve(fullName string, version *semver.Version, ctx map[string]string) (*Binary, error)

Directories

Path Synopsis
Package template provides helpers for binary templates.
Package template provides helpers for binary templates.

Jump to

Keyboard shortcuts

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