golang.org/x/tools@v0.21.1-0.20240520172518-788d39e776b1/internal/versions/types.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 versions 6 7 import ( 8 "go/types" 9 ) 10 11 // GoVersion returns the Go version of the type package. 12 // It returns zero if no version can be determined. 13 func GoVersion(pkg *types.Package) string { 14 // TODO(taking): x/tools can call GoVersion() [from 1.21] after 1.25. 15 if pkg, ok := any(pkg).(interface{ GoVersion() string }); ok { 16 return pkg.GoVersion() 17 } 18 return "" 19 }