Documentation ¶
Overview ¶
Package version handles version types.
Index ¶
- Constants
- func ForSorting(version string) string
- func IsIncompatible(v string) bool
- func IsPseudo(v string) bool
- func Later(v1, v2 string) bool
- func LatestOf(versions []string) string
- func LatestVersion(versions []string, hasGoMod func(v string) (bool, error)) (v string, err error)
- func RemoveIf(s []string, f func(string) bool) []string
- type Type
Constants ¶
const ( // TypeRelease is a normal release. TypeRelease = Type("release") // TypePrerelease is a version with a prerelease. TypePrerelease = Type("prerelease") // TypePseudo appears to have a prerelease of the // form <commit date>-<commit hash>. TypePseudo = Type("pseudo") )
const ( // Latest signifies the latest available version in requests to the // proxy client. Latest = "latest" // Main represents the main branch. Main = "main" // Master represents the master branch. Master = "master" )
Variables ¶
This section is empty.
Functions ¶
func ForSorting ¶
ForSorting returns a string that encodes version, so that comparing two such strings follows SemVer precedence, https://semver.org clause 11. It assumes version is valid. The returned string ends in '~' if and only if the version does not have a prerelease.
For examples, see TestForSorting.
func IsIncompatible ¶
IsIncompatible reports whether a valid version v is an incompatible version.
func IsPseudo ¶
IsPseudo reports whether a valid version v is a pseudo-version. Modified from src/cmd/go/internal/modfetch.
func Later ¶
Later reports whether v1 is later than v2, using semver but preferring release versions to pre-release versions, and both to pseudo-versions.
func LatestOf ¶
LatestOf returns the latest version of a module from a list of versions, using the go command's definition of latest: semver is observed, except that release versions are preferred to prerelease, and both are preferred to pseudo-versions. If versions is empty, the empty string is returned.
func LatestVersion ¶
LatestVersion finds the latest version of a module using the same algorithm as the Go command. It prefers tagged release versions to tagged pre-release versions, and both of those to pseudo-versions. If versions is empty, LatestVersion returns the empty string.
hasGoMod should report whether the version it is given has a go.mod file. LatestVersion returns the latest incompatible version only if the latest compatible version does not have a go.mod file.
The meaning of latest is defined at https://golang.org/ref/mod#version-queries. That definition does not deal with retractions, or with a subtlety involving incompatible versions. The actual definition is embodied in the go command's queryMatcher.filterVersions method. This function is a re-implementation and specialization of that method at Go version 1.16 (https://go.googlesource.com/go/+/refs/tags/go1.16/src/cmd/go/internal/modload/query.go#441).