1
0
mirror of https://github.com/securego/gosec.git synced 2025-11-25 22:22:17 +02:00

fix: build tag parsing. (#1413)

* fix: build tag parsing.

* chore: lint fixes.
This commit is contained in:
Matthew Hartstonge
2025-11-05 22:46:27 +13:00
committed by GitHub
parent d2d734859c
commit 10cf58a4a4
8 changed files with 218 additions and 56 deletions

View File

@@ -553,3 +553,24 @@ func parseGoVersion(version string) (int, int, int) {
return major, minor, build
}
// CLIBuildTags converts a list of Go build tags into the corresponding CLI
// build flag (-tags=form) by trimming whitespace, removing empty entries,
// and joining them into a comma-separated -tags argument for use with go build
// commands.
func CLIBuildTags(buildTags []string) []string {
var buildFlags []string
if len(buildTags) > 0 {
for _, tag := range buildTags {
// remove empty entries and surrounding whitespace
if t := strings.TrimSpace(tag); t != "" {
buildFlags = append(buildFlags, t)
}
}
if len(buildFlags) > 0 {
buildFlags = []string{"-tags=" + strings.Join(buildFlags, ",")}
}
}
return buildFlags
}