Documentation
¶
Overview ¶
Package semver parses and compares Semantic Versioning 2.0.0 versions and evaluates version constraints shared by mods, library packs and plugins.
Versions follow MAJOR.MINOR.PATCH[-prerelease][+build] with an optional leading "v" (such as Go module versions and pseudo-versions). Build metadata is validated on parse and ignored in precedence and formatting; Version.String omits both "v" and build metadata.
Constraints are space- or comma-separated conjunctions of clauses using *, =, >=, >, <=, <, ^, and ~, with optional partial versions (MAJOR or MAJOR.MINOR) and optional leading "v". Every comparison uses pure SemVer 2.0.0 precedence via Version.Compare: pre-releases (including Go pseudo-versions) satisfy any range whose bounds bracket them (for example, >=1.0.0 matches 1.1.0-beta and v1.0.1-0.20261120093000-0123456789ab, and <2.0.0 matches 2.0.0-alpha unless written <2.0.0-0).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Constraint ¶
type Constraint struct {
// contains filtered or unexported fields
}
Constraint is a parsed version constraint composed of zero or more AND-ed clauses. The zero value matches every version.
func ParseConstraint ¶
func ParseConstraint(s string) (Constraint, error)
ParseConstraint parses a version constraint. Supported operators are *, =, >=, >, <=, <, ^, and ~ (or a bare version, equivalent to =), joined by spaces or commas. Clauses may use partial versions such as ^1.2 (>=1.2.0 <2.0.0), ~1.2 (>=1.2.0 <1.3.0), or >=1.2 (>=1.2.0), and an optional leading "v". An empty string or "*" matches every version.
func (Constraint) Check ¶
func (c Constraint) Check(v Version) bool
Check reports whether v satisfies every clause of c using SemVer 2.0.0 precedence.
func (Constraint) String ¶
func (c Constraint) String() string
String returns the trimmed constraint text, or "*" for an unconstrained zero value.
type Version ¶
Version is a parsed semantic version (MAJOR.MINOR.PATCH[-prerelease]).
func Parse ¶
Parse parses a SemVer 2.0.0 version string with an optional leading "v", such as "1.2.3", "v0.4.0", "0.4.0-beta.1", "v0.0.0-20261120093000-0123456789ab", or "v2.0.0+incompatible". Build metadata is validated and discarded.