yoake/internal/version/version.go

49 lines
846 B
Go
Raw Normal View History

2022-11-11 16:15:22 -06:00
package version
2022-11-15 10:55:23 -06:00
import (
"runtime/debug"
"time"
)
2022-11-15 10:31:27 -06:00
2022-11-11 16:15:22 -06:00
var (
2022-11-15 10:55:23 -06:00
tagVersion = ""
buildDate = "unknown"
Date = "unknown"
2022-11-15 10:31:27 -06:00
Version = func() string {
info, ok := debug.ReadBuildInfo()
if !ok {
return "unknown"
}
2022-11-15 10:55:23 -06:00
var vcsRevision string
var vcsTime time.Time
var vcsModified bool
for _, setting := range info.Settings {
switch setting.Key {
case "vcs.revision":
vcsRevision = setting.Value
case "vcs.time":
vcsTime, _ = time.Parse(time.RFC3339, setting.Value)
case "vcs.modified":
vcsModified = setting.Value != "false"
}
}
if tagVersion != "" {
vcsRevision = tagVersion
}
if vcsModified {
Date = buildDate
return vcsRevision + "+devel"
} else {
Date = buildDate
if !vcsTime.IsZero() {
Date = vcsTime.Format("2006-01-02T15:04Z07:00")
}
return vcsRevision
}
2022-11-15 10:31:27 -06:00
}()
2022-11-11 16:15:22 -06:00
)