semver

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 6 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 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

func Check

func Check(version, constraint string) (bool, error)

Check parses version and constraint and reports whether version satisfies constraint.

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

type Version struct {
	Major int
	Minor int
	Patch int
	Pre   string
}

Version is a parsed semantic version (MAJOR.MINOR.PATCH[-prerelease]).

func Parse

func Parse(s string) (Version, error)

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.

func (Version) Compare

func (v Version) Compare(o Version) int

Compare compares v and o according to SemVer 2.0.0 precedence. It returns -1 if v < o, 0 if v == o, and +1 if v > o.

func (Version) String

func (v Version) String() string

String formats v as MAJOR.MINOR.PATCH[-prerelease] without a leading "v".

Jump to

Keyboard shortcuts

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