Make sure some version information is set when no version was injected into the binary

Signed-off-by: Cosmin Cojocar <cosmin.cojocar@gmx.ch>
This commit is contained in:
Cosmin Cojocar 2020-06-19 10:28:01 +02:00 committed by Cosmin Cojocar
parent 1d2c951f2c
commit ad1cb7e47e
2 changed files with 18 additions and 0 deletions

View file

@ -240,6 +240,9 @@ func filterIssues(issues []*gosec.Issue, severity gosec.Score, confidence gosec.
}
func main() {
// Makes sure some version information is set
prepareVersionInfo()
// Setup usage description
flag.Usage = usage

View file

@ -1,5 +1,9 @@
package main
import (
"runtime/debug"
)
// Version is the build version
var Version string
@ -8,3 +12,14 @@ var GitTag string
// BuildDate is the date when the build was created
var BuildDate string
// prepareVersionInfo sets some runtime version when the version value
// was not injected by the build into the binary (e.g. go get).
// This returns currently "(devel)" but not an effective version until
// https://github.com/golang/go/issues/29814 gets resolved.
func prepareVersionInfo() {
if Version == "" {
bi, _ := debug.ReadBuildInfo()
Version = bi.Main.Version
}
}