version

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package version parses tags under a version scheme, builds the sorted set of a tool's versions, and selects the versions in a range.

Index

Constants

View Source
const (
	SchemeSemver = "semver"
	SchemeLoose  = "loose"
	SchemeCalver = "calver"
	SchemePython = "python"
	SchemeRegex  = "regex"
)

Scheme names, as used in registry entries.

Variables

View Source
var (
	ErrDowngrade    = errors.New("range goes backwards")
	ErrNotFound     = errors.New("version not found")
	ErrLineMismatch = errors.New("range leaves the release line")
)

Range selection errors.

View Source
var ErrNoMatch = errors.New("no version satisfies the constraint")

ErrNoMatch is returned when no version satisfies a constraint.

View Source
var ErrParse = errors.New("invalid version")

ErrParse is wrapped by every parse error.

Functions

func SchemeNames

func SchemeNames() []string

SchemeNames lists every scheme name.

Types

type Constraint

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

Constraint is a comma-separated list of terms that must all hold, such as "~> 1.15" or ">= 1.2, < 2". Operators: =, !=, >, >=, <, <= and ~> (pessimistic: "~> 1.15" allows 1.x from 1.15 on, "~> 1.15.3" allows 1.15.x from 1.15.3 on).

func ParseConstraint

func ParseConstraint(s Scheme, expr string) (Constraint, error)

ParseConstraint parses expr with versions read under s.

func (Constraint) Check

func (c Constraint) Check(v V) bool

Check reports whether v satisfies every term.

func (Constraint) Floor

func (c Constraint) Floor() (V, bool)

Floor returns the lowest version c allows without a version list: its highest inclusive lower bound (=, >= or ~>), padded to three segments. The second result is false when c has no inclusive lower bound, when an exclusive bound (>) sits at or above it, or when the bound itself fails another term, as in ">= 1.5, != 1.5.0".

func (Constraint) String

func (c Constraint) String() string

String returns the constraint as written.

type Level

type Level string

Level is a release line granularity.

const (
	LineNone  Level = "none"
	LineMajor Level = "major"
	LineMinor Level = "minor"
)

Line levels: none allows any newer version, major keeps the major, minor keeps major.minor.

func ParseLevel

func ParseLevel(s string) (Level, error)

ParseLevel validates a line level. The empty string means LineNone.

type Pick

type Pick string

Pick says how Universe.ResolveConstraint chose a version.

const (
	PickKnown  Pick = "highest installed or locked version"
	PickLowest Pick = "lowest satisfying version"
)

Ways a constraint pin becomes a version.

type Range

type Range struct {
	From        V        // as requested
	Base        *Version // the version the range starts after: From, the nearest lower one, or nil
	To          Version
	Versions    []Version // (From, To], oldest first
	Prereleases bool      // whether prereleases were included
	Warnings    []string
}

Range is the result of Universe.Select.

type RangeOptions

type RangeOptions struct {
	From               string
	To                 string // empty means the latest stable version on the line
	Line               Level
	IncludePrereleases bool // also on when From or To is itself a prerelease
}

RangeOptions selects the versions in (From, To].

type Ref

type Ref struct {
	Tag         string
	Draft       bool
	Prerelease  bool // the forge's prerelease flag; the scheme can also mark one
	PublishedAt time.Time
}

Ref is a tag or a release as the forge lists it.

type Rules

type Rules struct {
	Scheme    Scheme
	TagPrefix string         // stripped before parsing; tags without it are dropped
	Exclude   *regexp.Regexp // matched against the whole tag; matching tags are dropped
}

Rules turn tags into versions.

type Scheme

type Scheme interface {
	Name() string
	Parse(s string) (V, error)
	Compare(a, b V) int
	IsPrerelease(v V) bool
	Line(v V, level Level) string
}

Scheme parses and orders the versions of one tool.

func Calver

func Calver() Scheme

Calver returns the calendar versioning scheme: numeric segments compared as integers ("2026.11.5", "2026.1"), with an optional "-suffix" marking a prerelease.

func Loose

func Loose() Scheme

Loose returns a lenient scheme for versions that aren't semver: any number of segments ("2.35.3.1"), Go's "go1.20" and "go1.21rc2", and build metadata ("21.0.9+10", ignored when comparing).

func NewScheme

func NewScheme(name, extract string) (Scheme, error)

NewScheme returns the named scheme. extract is the regular expression for SchemeRegex and must be empty for the others.

func Python

func Python() Scheme

Python returns a PEP 440 subset: release segments, a/b/rc prereleases, .postN and .devN. Epochs and local versions are rejected.

func Regex

func Regex(extract string) (Scheme, error)

Regex returns a scheme that applies extract to the tag and parses its capture groups, joined with ".", under Loose. Without capture groups the whole match is used.

func Semver

func Semver() Scheme

Semver returns the semantic versioning scheme. A leading "v" is accepted.

type Universe

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

Universe is the set of a tool's versions, sorted ascending by its scheme.

func NewUniverse

func NewUniverse(ctx context.Context, logger *slog.Logger, refs []Ref, rules Rules) *Universe

NewUniverse parses refs under rules. Drafts, excluded tags and tags that don't parse are dropped, and versions that compare equal ("3.7.12" and "v3.7.12") are kept once, as the first one in refs. Order comes from the scheme, never from publish dates.

func (*Universe) Latest

func (u *Universe) Latest(from V, level Level) (Version, bool)

Latest returns the newest stable version on from's release line. With LineNone or a zero from it returns the newest stable version.

func (*Universe) Parse

func (u *Universe) Parse(s string) (V, error)

Parse parses user input such as "1.30.0", "v1.30.0" or the full tag "atlascli/v1.30.0".

func (*Universe) ResolveConstraint

func (u *Universe) ResolveConstraint(c Constraint, known []V) (V, Pick, error)

ResolveConstraint returns the version a constraint pin stands for: the highest of known (installed or locked versions) that satisfies c, otherwise the lowest stable version in the universe that does.

func (*Universe) ResolvePrefix

func (u *Universe) ResolvePrefix(prefix string) (V, error)

ResolvePrefix returns the version a prefix pin such as "26" or "1.2" stands for: the highest stable version whose leading release segments equal the prefix, which is what mise installs.

func (*Universe) Scheme

func (u *Universe) Scheme() Scheme

Scheme returns the scheme the universe was parsed with.

func (*Universe) Select

func (u *Universe) Select(opts RangeOptions) (*Range, error)

Select returns the versions after From up to and including To.

func (*Universe) Versions

func (u *Universe) Versions() []Version

Versions returns every version, oldest first.

type V

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

V is a version parsed by a Scheme. Only the scheme that parsed it can compare it.

func (V) IsZero

func (v V) IsZero() bool

IsZero reports whether v is the zero value.

func (V) String

func (v V) String() string

String returns the version text without a tag prefix or leading "v".

type Version

type Version struct {
	V           V
	Tag         string
	Prerelease  bool
	PublishedAt time.Time
}

Version is one entry of a Universe.

Jump to

Keyboard shortcuts

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