Skip to content

Commit ad1cb7e

Browse files
ccojocarCosmin Cojocar
authored and
Cosmin Cojocar
committed
Make sure some version information is set when no version was injected into the binary
Signed-off-by: Cosmin Cojocar <cosmin.cojocar@gmx.ch>
1 parent 1d2c951 commit ad1cb7e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

cmd/gosec/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ func filterIssues(issues []*gosec.Issue, severity gosec.Score, confidence gosec.
240240
}
241241

242242
func main() {
243+
// Makes sure some version information is set
244+
prepareVersionInfo()
245+
243246
// Setup usage description
244247
flag.Usage = usage
245248

cmd/gosec/version.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package main
22

3+
import (
4+
"runtime/debug"
5+
)
6+
37
// Version is the build version
48
var Version string
59

@@ -8,3 +12,14 @@ var GitTag string
812

913
// BuildDate is the date when the build was created
1014
var BuildDate string
15+
16+
// prepareVersionInfo sets some runtime version when the version value
17+
// was not injected by the build into the binary (e.g. go get).
18+
// This returns currently "(devel)" but not an effective version until
19+
// https://github.com/golang/go/issues/29814 gets resolved.
20+
func prepareVersionInfo() {
21+
if Version == "" {
22+
bi, _ := debug.ReadBuildInfo()
23+
Version = bi.Main.Version
24+
}
25+
}

0 commit comments

Comments
 (0)