version

package
v0.0.0-...-86cb477 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package version handles version types.

Index

Constants

View Source
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")
)
View Source
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

func ForSorting(version string) string

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

func IsIncompatible(v string) bool

IsIncompatible reports whether a valid version v is an incompatible version.

func IsPseudo

func IsPseudo(v string) bool

IsPseudo reports whether a valid version v is a pseudo-version. Modified from src/cmd/go/internal/modfetch.

func Later

func Later(v1, v2 string) bool

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

func LatestOf(versions []string) string

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

func LatestVersion(versions []string, hasGoMod func(v string) (bool, error)) (v string, err error)

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).

func RemoveIf

func RemoveIf(s []string, f func(string) bool) []string

RemoveIf returns a copy of s that omits all values for which f returns true.

Types

type Type

type Type string

Type defines the version types a module can have. This must be kept in sync with the 'version_type' database enum.

func ParseType

func ParseType(version string) (Type, error)

ParseType returns the Type of a given a version.

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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