github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/go/internal/gover/gover.go (about) 1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package gover implements support for Go toolchain versions like 1.21.0 and 1.21rc1. 6 // (For historical reasons, Go does not use semver for its toolchains.) 7 // This package provides the same basic analysis that golang.org/x/mod/semver does for semver. 8 // It also provides some helpers for extracting versions from go.mod files 9 // and for dealing with module.Versions that may use Go versions or semver 10 // depending on the module path. 11 package gover 12 13 // Compare returns -1, 0, or +1 depending on whether 14 // x < y, x == y, or x > y, interpreted as toolchain versions. 15 // The versions x and y must not begin with a "go" prefix: just "1.21" not "go1.21". 16 // Malformed versions compare less than well-formed versions and equal to each other. 17 // The language version "1.21" compares less than the release candidate and eventual releases "1.21rc1" and "1.21.0". 18 func Compare(x, y string) int 19 20 // Max returns the maximum of x and y interpreted as toolchain versions, 21 // compared using Compare. 22 // If x and y compare equal, Max returns x. 23 func Max(x, y string) string 24 25 // IsLang reports whether v denotes the overall Go language version 26 // and not a specific release. Starting with the Go 1.21 release, "1.x" denotes 27 // the overall language version; the first release is "1.x.0". 28 // The distinction is important because the relative ordering is 29 // 30 // 1.21 < 1.21rc1 < 1.21.0 31 // 32 // meaning that Go 1.21rc1 and Go 1.21.0 will both handle go.mod files that 33 // say "go 1.21", but Go 1.21rc1 will not handle files that say "go 1.21.0". 34 func IsLang(x string) bool 35 36 // Lang returns the Go language version. For example, Lang("1.2.3") == "1.2". 37 func Lang(x string) string 38 39 // IsPrerelease reports whether v denotes a Go prerelease version. 40 func IsPrerelease(x string) bool 41 42 // Prev returns the Go major release immediately preceding v, 43 // or v itself if v is the first Go major release (1.0) or not a supported 44 // Go version. 45 // 46 // Examples: 47 // 48 // Prev("1.2") = "1.1" 49 // Prev("1.3rc4") = "1.2" 50 func Prev(x string) string 51 52 // IsValid reports whether the version x is valid. 53 func IsValid(x string) bool