mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
Signed-off-by: Samuel Dacanay <sam.dacanay@anchore.com> Make json version output always verbose, cleanup struct tag Signed-off-by: Samuel Dacanay <sam.dacanay@anchore.com> Use camel case for json Signed-off-by: Samuel Dacanay <sam.dacanay@anchore.com>
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package version
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
)
|
|
|
|
const valueNotProvided = "[not provided]"
|
|
|
|
// all variables here are provided as build-time arguments, with clear default values
|
|
var version = valueNotProvided
|
|
var gitCommit = valueNotProvided
|
|
var gitTreeState = valueNotProvided
|
|
var buildDate = valueNotProvided
|
|
var platform = fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
|
|
|
|
// Version defines the application version details (generally from build information)
|
|
type Version struct {
|
|
Version string `json:"version"` // application semantic version
|
|
GitCommit string `json:"gitCommit"` // git SHA at build-time
|
|
GitTreeState string `json:"gitTreeState"` // indication of git tree (either "clean" or "dirty") at build-time
|
|
BuildDate string `json:"buildDate"` // date of the build
|
|
GoVersion string `json:"goVersion"` // go runtime version at build-time
|
|
Compiler string `json:"compiler"` // compiler used at build-time
|
|
Platform string `json:"platform"` // GOOS and GOARCH at build-time
|
|
}
|
|
|
|
// FromBuild provides all version details
|
|
func FromBuild() Version {
|
|
return Version{
|
|
Version: version,
|
|
GitCommit: gitCommit,
|
|
GitTreeState: gitTreeState,
|
|
BuildDate: buildDate,
|
|
GoVersion: runtime.Version(),
|
|
Compiler: runtime.Compiler,
|
|
Platform: platform,
|
|
}
|
|
}
|