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:
xgopilot
2025-10-16 02:33:53 +00:00
parent 938f883be9
commit 7fbcc8cd10

View File

@@ -13,13 +13,32 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
"strconv" "strconv"
"strings"
) )
// Type aliases to reference standard library types // Type aliases to reference standard library types
type Context = build.Context type Context = build.Context
// Go version constant (Go 1.24) // parseGoVersion extracts the minor version number from runtime.Version()
const goVersion = 24 // 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 defaultToolTags []string
var defaultReleaseTags []string var defaultReleaseTags []string