Louis :emacs: on Nostr: TIL: Go 1.18+ can read the Git revision the binary was built from during runtime: var ...
TIL: Go 1.18+ can read the Git revision the binary was built from during runtime:
var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}
}
return ""
}()
fmt.Printf("Git Rev. %s\n", commit)
Very useful to print the revision on startup to make sure you are actually using the right version.
#golang
var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}
}
return ""
}()
fmt.Printf("Git Rev. %s\n", commit)
Very useful to print the revision on startup to make sure you are actually using the right version.
#golang