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 ¶
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 ¶
NewCache creates a new cache with the given TTL. If path is non-empty, the cache will be persisted to disk.
func (*Cache) Set ¶
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).
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 ¶
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 ¶
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.
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 ¶
CachedResolverFor returns a cached resolver for a runtime.
func ResolverFor ¶
ResolverFor returns the appropriate resolver for a runtime dependency. Returns nil if no resolver exists for the given dependency.