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 ¶
- func Compare(a, b string) (result int, ok bool)
- func Highest(tags []string) string
- func IsPreRelease(text string) bool
- func List(text string) []string
- func SameLine(a, b string) bool
- func Satisfies(v, constraints string) (inRange bool, known bool)
- func Valid(text string) bool
- type Clause
- type Constraint
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
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 ¶
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 ¶
IsPreRelease reports whether text is a release candidate, nightly or other build that precedes a final release.
func List ¶
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 ¶
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.
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 ¶
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 ¶
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 ¶
Contains reports whether v satisfies every constraint of the clause. known is false when v cannot be compared.
func (Clause) LowerBound ¶
LowerBound returns the version the clause starts at, or "" when it has no lower bound.
type Constraint ¶
Constraint is one comparison against a version, such as ">= 9.2.0".