cachedeps

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 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
}

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 and SHA256 are keyed by the platforms supported. Subpath, optional and ignored when Format is Binary, names a specific entry inside an extracted archive (e.g., "go/bin/go"); when empty, Ensure returns the path to the extraction directory.

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