version

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 3 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 compares the version strings that advisories and release tags use: dotted numbers with an optional pre-release or post-release suffix (1.83.7, v4.3.0, 0.32.0rc0, 17.5.1-ee, 1.83.7-stable.patch.1).

Anything it cannot parse is reported as not comparable. Callers must then keep the advisory rather than drop it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(a, b string) (result int, ok bool)

Compare returns a negative number when a < b, zero when they are equal and a positive number when a > b. ok is false when either cannot be parsed.

func Highest

func Highest(tags []string) string

Highest returns the highest final version among tags, without a leading "v". Tags that are not versions and pre-releases are ignored. It returns "" when no tag qualifies.

func IsPreRelease

func IsPreRelease(text string) bool

IsPreRelease reports whether text is a release candidate, nightly or other build that precedes a final release.

func List

func List(text string) []string

List pulls the versions out of free text such as "9.3.2, 9.2.8, 8.5.16" or "4.0.0+". Anything that is not a version is skipped.

func SameLine

func SameLine(a, b string) bool

SameLine reports whether a and b are on the same release line: the same major and minor numbers, as 1.106.6 and 1.106.12 are.

func Satisfies

func Satisfies(v, constraints string) (inRange bool, known bool)

Satisfies reports whether v falls inside a range written as comma-separated constraints, such as ">= 0.32.0rc0, <= 0.34.0" or "< 1.106.9". known is false when the answer cannot be worked out.

func Valid

func Valid(text string) bool

Valid reports whether text parses as a version.

Types

type Clause

type Clause []Constraint

Clause is a set of constraints that must all hold. A range is one or more clauses, any one of which may hold.

func ParseRange

func ParseRange(text string) (clauses []Clause, ok bool)

ParseRange reads an affected-version range the way advisories write them. Project advisories are free text, so it accepts several styles:

>= 0.32.0rc0, <= 0.34.0             one clause
< 9.0.3, < 8.5.9                    one clause per release line
>=9.2.0 <9.2.10 >=9.3.0 <9.3.4      two bounded clauses
8.0.0 - 8.3.0                       a hyphen range
Grafana Enterprise 8.1.0 - 8.4.5    words are skipped

ok is false when any part cannot be understood, as with "<9.x". The caller must then treat the range as unknown, never as empty.

func (Clause) Bounded

func (c Clause) Bounded() bool

Bounded reports whether the clause pins versions down from both sides: it has a lower and an upper bound, or names one exact version. A bounded clause is a deliberate statement and is taken as written. An open-ended one, such as ">= 9.2.0" alone, usually means "until the fix".

func (Clause) Contains

func (c Clause) Contains(v string) (in bool, known bool)

Contains reports whether v satisfies every constraint of the clause. known is false when v cannot be compared.

func (Clause) LowerBound

func (c Clause) LowerBound() string

LowerBound returns the version the clause starts at, or "" when it has no lower bound.

type Constraint

type Constraint struct {
	Op      string
	Version string
}

Constraint is one comparison against a version, such as ">= 9.2.0".

Jump to

Keyboard shortcuts

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