cachedeps

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package cachedeps downloads and caches pinned files and archives under the per-user OS cache directory (e.g., ${XDG_CACHE_HOME} on Linux, ~/Library/Caches on macOS), so programs use the same artifact versions across machines.

Every dependency is cached at <cache>/<subdir>/<key>: a single file for `Binary` deps, a directory of extracted contents for `TarGz` and `Zip`. The cache key is "<name>-<version>", or just "<name>" when Version is empty. The `Subpath` field on Dependency picks a single entry inside an extracted archive; when empty, `Ensure` returns the extraction directory itself.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// Subdir is the per-application directory under the OS cache root,
	// e.g., "myapp". Required.
	Subdir string
	// Output receives progress messages ("Downloading...", progress
	// bar). If nil, progress output is silent.
	Output io.Writer
}

Cache stores binary dependencies under <os-cache>/<Subdir>, where <os-cache> is the per-user OS cache directory returned by os.UserCacheDir() (e.g., ${XDG_CACHE_HOME} on Linux, ~/Library/Caches on macOS).

func New

func New(subdir string) *Cache

New returns a Cache keyed by subdir with silent output.

func (*Cache) Ensure

func (c *Cache) Ensure(dep Dependency) (string, error)

Ensure returns the filesystem path to the cached executable for dep, downloading and extracting on first use. Subsequent calls hit the cache and skip the download.

func (*Cache) Root

func (c *Cache) Root() (string, error)

Root returns the absolute directory under which this Cache stores dependencies, resolving os.UserCacheDir() at call time.

type Dependency

type Dependency struct {
	Name    string
	Version string
	Format  Format
	URLs    map[Platform]string
	SHA256  map[Platform]string
	Subpath string
	Strip   int
}

Dependency describes one cacheable artifact. Name is required. Version is optional and, when set, becomes part of the on-disk cache key so different versions sit side by side. URLs are keyed by the platforms supported. SHA256 is keyed the same way and may be left nil or empty to skip checksum verification; when SHA256 is non-empty but lacks an entry for the host platform, Ensure errors out rather than silently skipping. Subpath, optional and ignored when Format is Binary, restricts extraction to a single file or directory subtree within the archive: only entries matching Subpath exactly or sitting under Subpath + "/" are written to the cache. Match is against the raw archive path -- if the archive wraps its contents in `wrap/` then `Subpath: "wrap"` is the full directory, not `Subpath: "models"` which names something that doesn't exist at the archive root. When Subpath is empty, the whole archive is extracted. Strip drops the first N path components from each extracted entry's path (analogous to tar --strip-components); 0 leaves the layout as is, and Strip is ignored when Format is Binary. Strip must not exceed the number of components in Subpath when Subpath is set -- otherwise the matched entries would have nothing left and Ensure errors out.

func (Dependency) CacheKey

func (d Dependency) CacheKey() string

CacheKey returns the on-disk name for this dependency: "<name>-<version>" when Version is set, or just "<name>" when it is empty.

func (Dependency) Path

func (d Dependency) Path(c *Cache) (string, error)

Path returns the absolute filesystem path where this dependency is cached under c, without performing any I/O. The path may not exist yet if Ensure has not been called. Useful for handing to exec.Command after Ensure.

type Format

type Format int

Format names how a Dependency is delivered.

const (
	// Binary is a single executable file at the URL.
	Binary Format = iota
	// TarGz is a gzipped tar archive containing the executable.
	TarGz
	// Zip is a zip archive containing the executable.
	Zip
)

type Platform

type Platform struct {
	OS   string
	Arch string
}

Platform identifies a target OS and architecture.

Jump to

Keyboard shortcuts

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