go-project-template/config/version.go

29 lines
392 B
Go
Raw Permalink Normal View History

2024-07-24 07:53:20 +00:00
package config
import (
"runtime/debug"
"github.com/sirupsen/logrus"
)
var (
BuildInfo *debug.BuildInfo
Version string
)
2024-07-24 07:53:20 +00:00
func init() {
var ok bool
BuildInfo, ok = debug.ReadBuildInfo()
if !ok {
logrus.Error("failed to read build info")
return
}
for _, setting := range BuildInfo.Settings {
if setting.Key == "vcs.revision" {
Version = setting.Value
break
}
}
2024-07-24 07:53:20 +00:00
}