package semver
Import Path
golang.org/x/mod/semver (on go.dev)
Dependency Relation
imports 0 packages, and imported by 12 packages
Involved Source Files
Package semver implements comparison of semantic version strings.
In this package, semantic version strings must begin with a leading "v",
as in "v1.0.0".
The general form of a semantic version string accepted by this package is
vMAJOR[.MINOR[.PATCH[-PRERELEASE][+BUILD]]]
where square brackets indicate optional parts of the syntax;
MAJOR, MINOR, and PATCH are decimal integers without extra leading zeros;
PRERELEASE and BUILD are each a series of non-empty dot-separated identifiers
using only alphanumeric characters and hyphens; and
all-numeric PRERELEASE identifiers must not have leading zeros.
This package follows Semantic Versioning 2.0.0 (see semver.org)
with two exceptions. First, it requires the "v" prefix. Second, it recognizes
vMAJOR and vMAJOR.MINOR (with no prerelease or build suffixes)
as shorthands for vMAJOR.0.0 and vMAJOR.MINOR.0.
Package-Level Type Names (only one, which is unexported)
Package-Level Functions (total 18, in which 8 are exported)
Build returns the build suffix of the semantic version v.
For example, Build("v2.1.0+meta") == "+meta".
If v is an invalid semantic version string, Build returns the empty string.
Canonical returns the canonical formatting of the semantic version v.
It fills in any missing .MINOR or .PATCH and discards build metadata.
Two semantic versions compare equal only if their canonical formattings
are identical strings.
The canonical invalid semantic version is the empty string.
Compare returns an integer comparing two versions according to
semantic version precedence.
The result will be 0 if v == w, -1 if v < w, or +1 if v > w.
An invalid semantic version string is considered less than a valid one.
All invalid semantic version strings compare equal to each other.
IsValid reports whether v is a valid semantic version string.
Major returns the major version prefix of the semantic version v.
For example, Major("v2.1.0") == "v2".
If v is an invalid semantic version string, Major returns the empty string.
MajorMinor returns the major.minor version prefix of the semantic version v.
For example, MajorMinor("v2.1.0") == "v2.1".
If v is an invalid semantic version string, MajorMinor returns the empty string.
Max canonicalizes its arguments and then returns the version string
that compares greater.
Prerelease returns the prerelease suffix of the semantic version v.
For example, Prerelease("v2.1.0-pre+meta") == "-pre".
If v is an invalid semantic version string, Prerelease returns the empty string.
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |