gover

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2024 License: MIT Imports: 3 Imported by: 1

README

gover

fix for std go/version see Issue #68384

Documentation

Overview

Package gover provides operations on Go versions in Go toolchain name syntax: strings like "go1.20", "go1.21.0", "go1.22rc2", and "go1.23.4-bigcorp".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CmpInt

func CmpInt(x, y string) int

CmpInt returns cmp.Compare(x, y) interpreting x and y as decimal numbers. (Copied from golang.org/x/mod/semver's compareInt.)

func Compare

func Compare(x, y string) int

Compare returns -1, 0, or +1 depending on whether x < y, x == y, or x > y, interpreted as Go versions. The versions x and y must begin with a "go" prefix: "go1.21" not "1.21". Invalid versions, including the empty string, compare less than valid versions and equal to each other. After go1.21, the language version is less than specific release versions or other prerelease versions. For example:

Compare("go1.21rc1", "go1.21") = 1
Compare("go1.21rc1", "go1.21.0") = -1
Compare("go1.22rc1", "go1.22") = 1
Compare("go1.22rc1", "go1.22.0") = -1

However, When the language version is below go1.21, the situation is quite different, because the initial release version was 1.N, not 1.N.0. For example:

Compare("go1.20rc1", "go1.21") = -1
Compare("go1.19rc1", "go1.19") = -1
Compare("go1.18", "go1.18rc1") = 1
Compare("go1.18", "go1.18rc1") = 1

This situation also happens to prerelease for some old patch versions, such as "go1.8.5rc5, "go1.9.2rc2" For example:

Compare("go1.8.5rc4", "go1.8.5rc5") = -1
Compare("go1.8.5rc5", "go1.8.5") = -1
Compare("go1.9.2rc2", "go1.9.2") = -1
Compare("go1.9.2rc2", "go1.9") = 1

func DecInt

func DecInt(decimal string) string

DecInt returns the decimal string decremented by 1, or the empty string if the decimal is all zeroes. (Copied from golang.org/x/mod/module's decDecimal.)

func IsValid

func IsValid(x string) bool

IsValid reports whether the version x is valid.

func Lang

func Lang(x string) string

Lang returns the Go language version for version x. If x is not a valid version, Lang returns the empty string. For example:

Lang("go1.21rc2") = "go1.21"
Lang("go1.21.2") = "go1.21"
Lang("go1.21") = "go1.21"
Lang("go1") = "go1"
Lang("bad") = ""
Lang("1.21") = ""

func Max

func Max(x, y string) string

Max returns the maximum of x and y interpreted as toolchain versions, compared using Compare. If x and y compare equal, Max returns x.

Types

type Version

type Version struct {
	Major string // decimal
	Minor string // decimal or ""
	Patch string // decimal or ""
	Kind  string // "", "alpha", "beta", "rc"
	Pre   string // decimal or ""
}

A Version is a parsed Go version: major[.Minor[.Patch]][kind[pre]] The numbers are the original decimal strings to avoid integer overflows and since there is very little actual math. (Probably overflow doesn't matter in practice, but at the time this code was written, there was an existing test that used go1.99999999999, which does not fit in an int on 32-bit platforms. The "big decimal" representation avoids the problem entirely.)

func Parse

func Parse(x string) (Version, error)

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

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