buildinfo: compile time variables
These expose entrypoints for -ldflag injections at compile time, containing metadata about build env + SCM
This commit is contained in:
parent
26485ab1e8
commit
16ab40f44d
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package build
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
var (
|
||||
// Git tag of this binary
|
||||
Version = "v0.0.0+devel"
|
||||
// Git hash of this binary
|
||||
CommitHash = "0000000000000000000000000000000000000000"
|
||||
// Enabled features of this binary
|
||||
Features = ""
|
||||
|
||||
knownFeatures = map[string]bool{}
|
||||
)
|
||||
|
||||
// Get the short Git hash
|
||||
func ShortHash() string {
|
||||
return CommitHash[:7]
|
||||
}
|
||||
|
||||
// Get list of features enabled
|
||||
func FeaturesList() []string {
|
||||
out := []string{}
|
||||
active := strings.Split(Features, ",")
|
||||
|
||||
for feature, _ := range knownFeatures {
|
||||
sy := "-"
|
||||
if slices.Contains(active, feature) {
|
||||
sy = "+"
|
||||
}
|
||||
out = append(out, sy+feature)
|
||||
}
|
||||
slices.Sort(out)
|
||||
|
||||
return out
|
||||
}
|
Loading…
Reference in New Issue