Source File
version.go
Belonging Package
go/types
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package types
import (
)
// A goVersion is a Go language version string of the form "go1.%d"
// where d is the minor version number. goVersion strings don't
// contain release numbers ("go1.20.1" is not a valid goVersion).
type goVersion string
// asGoVersion returns v as a goVersion (e.g., "go1.20.1" becomes "go1.20").
// If v is not a valid Go version, the result is the empty string.
func asGoVersion( string) goVersion {
return goVersion(version.Lang())
}
// isValid reports whether v is a valid Go version.
func ( goVersion) () bool {
return != ""
}
// cmp returns -1, 0, or +1 depending on whether x < y, x == y, or x > y,
// interpreted as Go versions.
func ( goVersion) ( goVersion) int {
return version.Compare(string(), string())
}
var (
// Go versions that introduced language changes
go1_9 = asGoVersion("go1.9")
go1_13 = asGoVersion("go1.13")
go1_14 = asGoVersion("go1.14")
go1_17 = asGoVersion("go1.17")
go1_18 = asGoVersion("go1.18")
go1_20 = asGoVersion("go1.20")
go1_21 = asGoVersion("go1.21")
go1_22 = asGoVersion("go1.22")
go1_23 = asGoVersion("go1.23")
// current (deployed) Go version
go_current = asGoVersion(fmt.Sprintf("go1.%d", goversion.Version))
)
// allowVersion reports whether the current effective Go version
// (which may vary from one file to another) is allowed to use the
// feature version (want).
func ( *Checker) ( goVersion) bool {
return !.version.isValid() || .version.cmp() >= 0
}
// verifyVersionf is like allowVersion but also accepts a format string and arguments
// which are used to report a version error if allowVersion returns false.
func ( *Checker) ( positioner, goVersion, string, ...interface{}) bool {
if !.allowVersion() {
.versionErrorf(, , , ...)
return false
}
return true
}
The pages are generated with Golds v0.7.3-preview. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |