Enable setting rev via -ldflags
This commit is contained in:
parent
d80ac09122
commit
cb6e3b72a8
22
core/info.go
22
core/info.go
@ -2,15 +2,21 @@ package core
|
||||
|
||||
import "runtime/debug"
|
||||
|
||||
// Set via -ldflags "-X github.com/Jaculabilis/intake/core.Commit=..."
|
||||
var Commit string = ""
|
||||
|
||||
func GetRevInfo() (rev string) {
|
||||
rev = ""
|
||||
if info, ok := debug.ReadBuildInfo(); ok {
|
||||
for _, setting := range info.Settings {
|
||||
if setting.Key == "vcs.revision" {
|
||||
rev = setting.Value + rev
|
||||
}
|
||||
if setting.Key == "vcs.modified" && setting.Value == "true" {
|
||||
rev = rev + "-dirty"
|
||||
rev = Commit
|
||||
if rev == "" {
|
||||
// No build data embedded, try from runtime/debug
|
||||
if info, ok := debug.ReadBuildInfo(); ok {
|
||||
for _, setting := range info.Settings {
|
||||
if setting.Key == "vcs.revision" {
|
||||
rev = setting.Value + rev
|
||||
}
|
||||
if setting.Key == "vcs.modified" && setting.Value == "true" {
|
||||
rev = rev + "-dirty"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user