versions

package
v0.27.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	Go1_18 = "go1.18"
	Go1_19 = "go1.19"
	Go1_20 = "go1.20"
	Go1_21 = "go1.21"
	Go1_22 = "go1.22"
)

GoVersions that features in x/tools can be gated to.

View Source
const Future = ""

Future is an invalid unknown Go version sometime in the future. Do not use directly with Compare.

Variables

View Source
var ConstraintGoVersion func(x constraint.Expr) string

ConstraintGoVersion is constraint.GoVersion (if built with go1.21+). Otherwise nil.

Deprecate once x/tools is after go1.21.

Functions

func AtLeast added in v0.19.0

func AtLeast(v, release string) bool

AtLeast reports whether the file version v comes after a Go release.

Use this predicate to enable a behavior once a certain Go release has happened (and stays enabled in the future).

func Before added in v0.19.0

func Before(v, release string) bool

Before reports whether the file version v is strictly before a Go release.

Use this predicate to disable a behavior once a certain Go release has happened (and stays enabled in the future).

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. The language version "go1.21" compares less than the release candidate and eventual releases "go1.21rc1" and "go1.21.0". Custom toolchain suffixes are ignored during comparison: "go1.21.0" and "go1.21.0-bigcorp" are equal.

func FileVersion added in v0.19.0

func FileVersion(info *types.Info, file *ast.File) string

FileVersion returns a file's Go version. The reported version is an unknown Future version if a version cannot be determined.

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") = ""

Types

This section is empty.

Jump to

Keyboard shortcuts

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