versions

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package versions provides version resolution for runtime dependencies. It fetches available versions from upstream APIs and resolves partial version specifications (e.g., "1.22") to full versions (e.g., "1.22.12").

Index

Constants

View Source
const DefaultCacheTTL = 24 * time.Hour

DefaultCacheTTL is the default time-to-live for cached version resolutions.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache stores resolved versions with TTL.

func DefaultCache

func DefaultCache() *Cache

DefaultCache returns a cache using the default moat cache directory.

func NewCache

func NewCache(ttl time.Duration, path string) *Cache

NewCache creates a new cache with the given TTL. If path is non-empty, the cache will be persisted to disk.

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all entries from the cache.

func (*Cache) Get

func (c *Cache) Get(key string) (string, bool)

Get retrieves a cached version if it exists and hasn't expired.

func (*Cache) Set

func (c *Cache) Set(key, version string)

Set stores a resolved version in the cache.

Concurrency note: When multiple goroutines call Set concurrently, the in-memory cache is always consistent (protected by mutex), but the persisted file may not reflect the exact final state if writes interleave. This is acceptable for a cache with 24h TTL - on next startup, the cache will be reloaded and stale entries will be re-resolved as needed.

type CachedResolver

type CachedResolver struct {
	Resolver Resolver
	Cache    *Cache
	Runtime  string // "go", "node", "python"
}

CachedResolver wraps a Resolver with caching.

func (*CachedResolver) Available

func (r *CachedResolver) Available(ctx context.Context) ([]string, error)

Available returns available versions (not cached, as it's informational).

func (*CachedResolver) LatestStable

func (r *CachedResolver) LatestStable(ctx context.Context) (string, error)

LatestStable returns the latest stable version (cached).

func (*CachedResolver) Resolve

func (r *CachedResolver) Resolve(ctx context.Context, version string) (string, error)

Resolve resolves a version, using the cache if available.

type GoResolver

type GoResolver struct {
	// HTTPClient is the HTTP client to use. If nil, http.DefaultClient is used.
	HTTPClient *http.Client
}

GoResolver resolves Go versions using the go.dev API.

func (*GoResolver) Available

func (r *GoResolver) Available(ctx context.Context) ([]string, error)

Available returns all stable Go versions, newest first.

func (*GoResolver) LatestStable

func (r *GoResolver) LatestStable(ctx context.Context) (string, error)

LatestStable returns the latest stable Go version.

func (*GoResolver) Resolve

func (r *GoResolver) Resolve(ctx context.Context, version string) (string, error)

Resolve resolves a Go version specification to a full version. Examples:

  • "1.22" -> "1.22.12" (latest patch)
  • "1.25" -> "1.25.6" (latest patch)
  • "1.22.5" -> "1.22.5" (exact, verified to exist)

Pre-release versions (e.g., "1.23rc1", "1.23beta1") are not supported. Only stable releases are resolved. Requesting a pre-release version will return an error. Use exact version syntax for pre-release builds.

type NodeResolver

type NodeResolver struct {
	// HTTPClient is the HTTP client to use. If nil, http.DefaultClient is used.
	HTTPClient *http.Client
}

NodeResolver resolves Node.js versions using the nodejs.org API.

func (*NodeResolver) Available

func (r *NodeResolver) Available(ctx context.Context) ([]string, error)

Available returns all Node.js versions, newest first.

func (*NodeResolver) LatestStable

func (r *NodeResolver) LatestStable(ctx context.Context) (string, error)

LatestStable returns the latest LTS Node.js version.

func (*NodeResolver) Resolve

func (r *NodeResolver) Resolve(ctx context.Context, version string) (string, error)

Resolve resolves a Node.js version specification to a full version. Accepts partial versions that are expanded to the latest matching release:

  • "20" -> "20.11.0" (latest in major 20)
  • "20.11" -> "20.11.1" (latest patch in 20.11.x)
  • "20.11.0" -> "20.11.0" (exact, verified to exist)

Pre-release versions are not filtered out but are not specially handled. The resolver returns stable releases; nightly or RC builds should use exact version syntax if needed.

type PythonResolver

type PythonResolver struct{}

PythonResolver resolves Python versions. Unlike Go and Node, Python doesn't have a simple JSON API for versions. We use a hardcoded list of commonly available versions that can be installed via deadsnakes PPA or official Docker images.

func (*PythonResolver) Available

func (r *PythonResolver) Available(ctx context.Context) ([]string, error)

Available returns all Python versions, newest first.

func (*PythonResolver) LatestStable

func (r *PythonResolver) LatestStable(ctx context.Context) (string, error)

LatestStable returns the latest stable Python version.

func (*PythonResolver) Resolve

func (r *PythonResolver) Resolve(ctx context.Context, version string) (string, error)

Resolve resolves a Python version specification to a full version. Examples:

  • "3.11" -> "3.11.11" (latest patch)
  • "3.12" -> "3.12.8" (latest patch)
  • "3.11.5" -> "3.11.5" (exact, verified to exist)

type Resolver

type Resolver interface {
	// Resolve turns a partial version into a full version.
	// For example, "1.22" might resolve to "1.22.12".
	// If version is already fully specified and valid, it returns as-is.
	// Returns an error if the version doesn't exist or can't be resolved.
	Resolve(ctx context.Context, version string) (string, error)

	// Available returns all available stable versions, newest first.
	Available(ctx context.Context) ([]string, error)

	// LatestStable returns the latest stable version.
	LatestStable(ctx context.Context) (string, error)
}

Resolver resolves partial version specifications to full versions.

func CachedResolverFor

func CachedResolverFor(runtime string, cache *Cache) Resolver

CachedResolverFor returns a cached resolver for a runtime.

func ResolverFor

func ResolverFor(dep string) Resolver

ResolverFor returns the appropriate resolver for a runtime dependency. Returns nil if no resolver exists for the given dependency.

Jump to

Keyboard shortcuts

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