-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathruntime.go
44 lines (37 loc) · 1.1 KB
/
runtime.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package logging
import "runtime/debug"
const (
// BuildCommitChars is the number of characters to show in the build commit.
BuildCommitChars = 7
)
var (
// buildCommit is the git source commit (only first BuildCommitChars characters).
// Use linker flag to customize it: -X 'github.com/osbuild/logging.buildCommit=1234567
buildCommit string
// buildTime is the build time, if VCS is available
// Use linker flag to customize it: -X 'github.com/osbuild/logging.buildTime=2021-01-01T00:00:00Z'
buildTime string
)
func init() {
if bi, ok := debug.ReadBuildInfo(); ok {
for _, bs := range bi.Settings {
switch bs.Key {
case "vcs.revision":
if len(bs.Value) > BuildCommitChars {
buildCommit = bs.Value[0:BuildCommitChars]
}
case "vcs.time":
buildTime = bs.Value
}
}
}
}
// BuildID returns the build ID, typically a git commit but can be overriden via a linker flag.
// This is the short version, up to BuildCommitChars characters long.
func BuildID() string {
return buildCommit
}
// BuildTime returns the build time, if available.
func BuildTime() string {
return buildTime
}