Extracts and exposes VCS revision and build time information from Go build metadata. Use this to track deployment versions in distributed services.
// Source: https://github.com/openmeterio/openmeter | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
package main
import "runtime/debug"
// Provisioned by ldflags.
var version string
//nolint:gochecknoglobals
var (
revision string
revisionDate string
)
//nolint:gochecknoinits,goconst
func init() {
if version == "" {
version = "unknown"
}
buildInfo, _ := debug.ReadBuildInfo()
revision = "unknown"
revisionDate = "unknown"
for _, setting := range buildInfo.Settings {
if setting.Key == "vcs.revision" {
revision = setting.Value
}
if setting.Key == "vcs.time" {
revisionDate = setting.Value
}
}
}
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key