Standard library / go/build/constraint

go/build/constraint.GoVersion()

Returns the minimum structurally implied Go release tag, or empty when none is required. It is not a satisfiability solver. Expected stdout: 'go1.22\n'.

Formal Syntax & Structure

go syntaxgo
func GoVersion(x Expr) string

Parameters & Attributes

NameTypeDescription
xExprInput constant or Go value as specified by the function.

Return Value

string

Returns the minimum structurally implied Go release tag, or empty when none is required.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/build/constraint")
func check(e error) {  if e != nil {    panic(e)  }}
func main() {  x, e := constraint.Parse("//go:build linux && go1.22")  check(e)  fmt.Println(constraint.GoVersion(x))}
Go Reference