Source File
version.go
Belonging Package
go/version
// Copyright 2023 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 version provides operations on [Go versions]// in [Go toolchain name syntax]: strings like// "go1.20", "go1.21.0", "go1.22rc2", and "go1.23.4-bigcorp".//// [Go versions]: https://go.dev/doc/toolchain#version// [Go toolchain name syntax]: https://go.dev/doc/toolchain#namepackage version // import "go/version"import ()// stripGo converts from a "go1.21-bigcorp" version to a "1.21" version.// If v does not start with "go", stripGo returns the empty string (a known invalid version).func ( string) string {, _, _ = strings.Cut(, "-") // strip -bigcorp suffix.if len() < 2 || [:2] != "go" {return ""}return [2:]}// 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 ( string) string {:= gover.Lang(stripGo())if == "" {return ""}if strings.HasPrefix([2:], ) {return [:2+len()] // "go"+v without allocation} else {return "go" +}}// 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".func (, string) int {return gover.Compare(stripGo(), stripGo())}// IsValid reports whether the version x is valid.func ( string) bool {return gover.IsValid(stripGo())}
The pages are generated with Golds v0.7.6. (GOOS=linux GOARCH=amd64)