refactor: use runtime.Version() instead of hardcoded goVersion
Replaced hardcoded goVersion constant with parseGoVersion() function that dynamically extracts the Go version from runtime.Version(). This eliminates the need to update the version manually. 🤖 Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <luoliwoshang@users.noreply.github.com>
This commit is contained in:
@@ -13,13 +13,32 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Type aliases to reference standard library types
|
||||
type Context = build.Context
|
||||
|
||||
// Go version constant (Go 1.24)
|
||||
const goVersion = 24
|
||||
// parseGoVersion extracts the minor version number from runtime.Version()
|
||||
// e.g., "go1.24" or "go1.24.1" -> 24
|
||||
func parseGoVersion() int {
|
||||
v := runtime.Version()
|
||||
// Strip "go" prefix
|
||||
if strings.HasPrefix(v, "go") {
|
||||
v = v[2:]
|
||||
}
|
||||
// Extract version like "1.24" or "1.24.1"
|
||||
parts := strings.Split(v, ".")
|
||||
if len(parts) >= 2 {
|
||||
if minor, err := strconv.Atoi(parts[1]); err == nil {
|
||||
return minor
|
||||
}
|
||||
}
|
||||
// Fallback to a reasonable default if parsing fails
|
||||
return 24
|
||||
}
|
||||
|
||||
var goVersion = parseGoVersion()
|
||||
|
||||
var defaultToolTags []string
|
||||
var defaultReleaseTags []string
|
||||
|
||||
Reference in New Issue
Block a user