mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
39 lines
591 B
Go
39 lines
591 B
Go
package common
|
|
|
|
import "runtime/debug"
|
|
|
|
// GetVersion returns the current git commit hash.
|
|
func GetGoVersion() string {
|
|
var version string
|
|
|
|
bi, ok := debug.ReadBuildInfo()
|
|
if ok {
|
|
version = bi.GoVersion
|
|
}
|
|
|
|
return version
|
|
}
|
|
|
|
// GetVersion returns the current git commit hash.
|
|
func GetCommit() string {
|
|
var revision string
|
|
var short string
|
|
|
|
bi, ok := debug.ReadBuildInfo()
|
|
if ok {
|
|
for _, s := range bi.Settings {
|
|
switch s.Key {
|
|
case "vcs.revision":
|
|
revision = s.Value
|
|
short = revision[:7]
|
|
}
|
|
}
|
|
}
|
|
|
|
if revision == "" {
|
|
return "unavailable"
|
|
}
|
|
|
|
return short
|
|
}
|