engine

package
v0.0.0-...-ef3cf1b Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OSDarwin = OS{
				// contains filtered or unexported fields
	}
	OSWindows = OS{
				// contains filtered or unexported fields
	}
	OSLinux = OS{
			// contains filtered or unexported fields
	}
	OSNetBSD = OS{
				// contains filtered or unexported fields
	}
	OSFreeBSD = OS{
				// contains filtered or unexported fields
	}
	OSOpenBSD = OS{
				// contains filtered or unexported fields
	}
	OSAndroid = OS{
				// contains filtered or unexported fields
	}
	OSIllumos = OS{
				// contains filtered or unexported fields
	}
	OSSolaris = OS{
				// contains filtered or unexported fields
	}
	OSPlan9 = OS{
			// contains filtered or unexported fields
	}
)
View Source
var (
	ArchAMD64 = Arch{
				// contains filtered or unexported fields
	}
	ArchI386 = Arch{
				// contains filtered or unexported fields
	}
	ArchArm = Arch{
			// contains filtered or unexported fields
	}
	ArchArm64 = Arch{
				// contains filtered or unexported fields
	}
	ArchRiscv64 = Arch{
				// contains filtered or unexported fields
	}
)
View Source
var ErrNoToken = errors.New("no github token")
View Source
var ErrNoUpgrade = errors.New("requested release is not more recent than current version")

Functions

func Cut

func Cut(s, sep string) (before, after string, found bool)

Cut is strings.Cut

func Download

func Download(url string, out io.Writer, getbar func(size int64) *pb.ProgressBar) error

Download the file at 'url' and write the http response body to 'out'. The 'getbar' function allows the caller to construct a progress bar given the size of the file being downloaded, and the download will write to the returned progress bar.

func DownloadConfigRepositories

func DownloadConfigRepositories(cfg *config.Config) error

func Get

func Get(url string) (*http.Response, error)

func IsDirectory

func IsDirectory(path string) bool

IsDirectory returns true if the file at path is a directory.

func IsGithubUrl

func IsGithubUrl(s string) bool

IsGithubUrl returns true if s is a URL with github.com as the host.

func IsLocalFile

func IsLocalFile(s string) bool

func IsUrl

func IsUrl(s string) bool

IsUrl returns true if s is a valid URL.

func ListAvailable

func ListAvailable(target string, opts options.Flags) ([]string, error)

func RefreshInstalledPackage

func RefreshInstalledPackage(pkg installed.Package) (installed.Package, error)

func Run

func Run(target string, opts options.Flags) error

func SetAuthHeader

func SetAuthHeader(req *http.Request) *http.Request

func SetDisableSSL

func SetDisableSSL(disable bool)

Types

type AllDetector

type AllDetector struct{}

AllDetector matches every asset. If there is only one asset, it is returned as a direct match. If there are multiple assets they are all returned as candidates.

func (*AllDetector) Detect

func (a *AllDetector) Detect(assets []string) (string, []string, error)

type Arch

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

An Arch represents a system architecture, such as amd64, i386, arm or others.

func (*Arch) Match

func (a *Arch) Match(s string) bool

Match returns true if this architecture is likely supported by the given archive name.

type Archive

type Archive interface {
	Next() (File, error)
	ReadAll() ([]byte, error)
}

func NewTarArchive

func NewTarArchive(data []byte, decompress DecompFn) (Archive, error)

func NewZipArchive

func NewZipArchive(data []byte, d DecompFn) (Archive, error)

decompressor does nothing for a zip archive because it already has built-in compression.

type ArchiveExtractor

type ArchiveExtractor struct {
	File       Chooser
	Ar         ArchiveFn
	Decompress DecompFn
}

func (*ArchiveExtractor) Extract

func (a *ArchiveExtractor) Extract(data []byte, multiple bool) (ExtractedFile, []ExtractedFile, error)

type ArchiveFn

type ArchiveFn func(data []byte, decomp DecompFn) (Archive, error)

type BinaryChooser

type BinaryChooser struct {
	Tool string
}

A BinaryChooser selects executable files. If the executable file has the name 'Tool' it is considered a direct match. If the file is only executable, it is a possible match.

func (*BinaryChooser) Choose

func (b *BinaryChooser) Choose(name string, dir bool, mode fs.FileMode) (bool, bool)

func (*BinaryChooser) String

func (b *BinaryChooser) String() string

type Chooser

type Chooser interface {
	Choose(name string, dir bool, mode fs.FileMode) (direct bool, possible bool)
}

A Chooser selects a file. It may list the file as a direct match (should be immediately extracted if found), or a possible match (only extract if it is the only match, or if the user manually requests it).

type DecompFn

type DecompFn func(r io.Reader) (io.Reader, error)

type Detector

type Detector interface {
	// Detect takes a list of possible assets and returns a direct match. If a
	// single direct match is not found, it returns a list of candidates and an
	// error explaining what happened.
	Detect(assets []string) (string, []string, error)
}

A Detector selects an asset from a list of possibilities.

type DetectorChain

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

func (*DetectorChain) Detect

func (dc *DetectorChain) Detect(assets []string) (string, []string, error)

type DirectAssetFinder

type DirectAssetFinder struct {
	URL string
}

A DirectAssetFinder returns the embedded URL directly as the only asset.

func (*DirectAssetFinder) Find

func (f *DirectAssetFinder) Find() ([]string, error)

type ExtractedFile

type ExtractedFile struct {
	Name        string // name to extract to
	ArchiveName string // name in archive

	Extract func(to string) error
	Dir     bool
	// contains filtered or unexported fields
}

An ExtractedFile contains the data, name, and permissions of a file in the archive.

func (ExtractedFile) Mode

func (e ExtractedFile) Mode() fs.FileMode

Mode returns the filemode of the extracted file.

func (ExtractedFile) String

func (e ExtractedFile) String() string

String returns the archive name of this extracted file

type Extractor

type Extractor interface {
	Extract(data []byte, multiple bool) (ExtractedFile, []ExtractedFile, error)
}

An Extractor reads in some archive data and extracts a particular file from it. If there are multiple candidates it returns a list and an error explaining what happened.

func NewExtractor

func NewExtractor(filename string, tool string, chooser Chooser) Extractor

NewExtractor constructs an extractor for the given archive file using the given chooser. It will construct extractors for files ending in '.tar.gz', '.tar.bz2', '.tar', '.zip'. After these matches, if the file ends with '.gz', '.bz2' it will be decompressed and copied. Other files will simply be copied without any decompression or extraction.

type File

type File struct {
	Name     string
	LinkName string
	Mode     fs.FileMode
	Type     FileType
}

func (File) Dir

func (f File) Dir() bool

type FileType

type FileType byte
const (
	TypeNormal FileType = iota
	TypeDir
	TypeLink
	TypeSymlink
	TypeOther
)

type Finder

type Finder interface {
	Find() ([]string, error)
}

A Finder returns a list of URLs making up a project's assets.

type GithubAssetFinder

type GithubAssetFinder struct {
	Repo       string
	Tag        string
	Prerelease bool
	MinTime    time.Time // release must be after MinTime to be found
	Digests    map[string]string
	ReleaseTag string
}

A GithubAssetFinder finds assets for the given Repo at the given tag. Tags must be given as 'tag/<tag>'. Use 'latest' to get the latest release.

func (*GithubAssetFinder) Find

func (f *GithubAssetFinder) Find() ([]string, error)

func (*GithubAssetFinder) FindMatch

func (f *GithubAssetFinder) FindMatch() ([]string, error)

type GithubError

type GithubError struct {
	Code   int
	Status string
	Body   []byte
	Url    string
}

func (*GithubError) Error

func (ge *GithubError) Error() string

type GithubRelease

type GithubRelease struct {
	Assets []struct {
		DownloadURL string `json:"browser_download_url"`
		Digest      string `json:"digest"`
	} `json:"assets"`

	Prerelease bool      `json:"prerelease"`
	Tag        string    `json:"tag_name"`
	CreatedAt  time.Time `json:"created_at"`
}

A GithubRelease matches the Assets portion of Github's release API json.

type GithubSourceFinder

type GithubSourceFinder struct {
	Tool string
	Repo string
	Tag  string
}

func (*GithubSourceFinder) Find

func (f *GithubSourceFinder) Find() ([]string, error)

type GlobChooser

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

func NewGlobChooser

func NewGlobChooser(gl string) (*GlobChooser, error)

func (*GlobChooser) Choose

func (gc *GlobChooser) Choose(name string, dir bool, mode fs.FileMode) (bool, bool)

func (*GlobChooser) String

func (gc *GlobChooser) String() string

type LiteralFileChooser

type LiteralFileChooser struct {
	File string
}

LiteralFileChooser selects files with the name 'File'.

func (*LiteralFileChooser) Choose

func (lf *LiteralFileChooser) Choose(name string, dir bool, mode fs.FileMode) (bool, bool)

func (*LiteralFileChooser) String

func (lf *LiteralFileChooser) String() string

type NoVerifier

type NoVerifier struct{}

func (*NoVerifier) Verify

func (n *NoVerifier) Verify(b []byte) error

type OS

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

An OS represents a target operating system.

func (*OS) Match

func (os *OS) Match(s string) (bool, bool)

Match returns true if the given archive name is likely to store a binary for this OS. Also returns if this is a priority match.

type RateLimit

type RateLimit struct {
	Limit     int
	Remaining int
	Reset     int64
}

func GetRateLimit

func GetRateLimit() (RateLimit, error)

func (RateLimit) ResetTime

func (r RateLimit) ResetTime() time.Time

func (RateLimit) String

func (r RateLimit) String() string

type RateLimitJson

type RateLimitJson struct {
	Resources map[string]RateLimit
}

type Sha256AssetVerifier

type Sha256AssetVerifier struct {
	AssetURL string
}

func (*Sha256AssetVerifier) Verify

func (s256 *Sha256AssetVerifier) Verify(b []byte) error

type Sha256Error

type Sha256Error struct {
	Expected []byte
	Got      []byte
}

func (*Sha256Error) Error

func (e *Sha256Error) Error() string

type Sha256Printer

type Sha256Printer struct{}

func (*Sha256Printer) Verify

func (s256 *Sha256Printer) Verify(b []byte) error

type Sha256Verifier

type Sha256Verifier struct {
	Expected []byte
}

func NewSha256Verifier

func NewSha256Verifier(expectedHex string) (*Sha256Verifier, error)

func (*Sha256Verifier) Verify

func (s256 *Sha256Verifier) Verify(b []byte) error

type SingleAssetDetector

type SingleAssetDetector struct {
	Asset string
	Anti  bool
	Regex *regexp.Regexp
}

SingleAssetDetector finds a single named asset. If Anti is true it finds all assets that don't contain Asset.

func (*SingleAssetDetector) Detect

func (s *SingleAssetDetector) Detect(assets []string) (string, []string, error)

type SingleFileExtractor

type SingleFileExtractor struct {
	Rename     string
	Name       string
	Decompress func(r io.Reader) (io.Reader, error)
}

SingleFileExtractor extracts files called 'Name' after decompressing the file with 'Decompress'.

func (*SingleFileExtractor) Extract

func (sf *SingleFileExtractor) Extract(data []byte, multiple bool) (ExtractedFile, []ExtractedFile, error)

type SystemDetector

type SystemDetector struct {
	Os   OS
	Arch Arch
}

A SystemDetector matches a particular OS/Arch system pair.

func NewSystemDetector

func NewSystemDetector(sos, sarch string) (*SystemDetector, error)

NewSystemDetector returns a new detector for the given OS/Arch as given by Go OS/Arch names.

func (*SystemDetector) Detect

func (d *SystemDetector) Detect(assets []string) (string, []string, error)

Detect extracts the assets that match this detector's OS/Arch pair. If one direct OS/Arch match is found, it is returned. If multiple OS/Arch matches are found they are returned as candidates. If multiple assets that only match the OS are found, and no full OS/Arch matches are found, the OS matches are returned as candidates. Otherwise all assets are returned as candidates.

type TarArchive

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

func (*TarArchive) Next

func (t *TarArchive) Next() (File, error)

func (*TarArchive) ReadAll

func (t *TarArchive) ReadAll() ([]byte, error)

type Verifier

type Verifier interface {
	Verify(b []byte) error
}

type ZipArchive

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

func (*ZipArchive) Next

func (z *ZipArchive) Next() (File, error)

func (*ZipArchive) ReadAll

func (z *ZipArchive) ReadAll() ([]byte, error)

Jump to

Keyboard shortcuts

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