Ver código fonte

go build version information.

Steve Thielemann 2 anos atrás
pai
commit
90ce0c7b0b
1 arquivos alterados com 57 adições e 0 exclusões
  1. 57 0
      testdoor/version.go

+ 57 - 0
testdoor/version.go

@@ -0,0 +1,57 @@
+package main
+
+import (
+	"fmt"
+	"runtime/debug"
+)
+
+func ShowVersion() {
+	var buildinfo *debug.BuildInfo
+	var ok bool
+	buildinfo, ok = debug.ReadBuildInfo()
+	if ok {
+		// We have build info, display it.
+		fmt.Print("Version: ")
+		var bs debug.BuildSetting
+		for _, bs = range buildinfo.Settings {
+			if bs.Key == "vcs.revision" || bs.Key == "vcs.time" {
+				fmt.Print(bs.Value + " ")
+			}
+		}
+		fmt.Println()
+	}
+}
+
+func GetVersion() (string, string) {
+	var buildinfo *debug.BuildInfo
+	var ok bool
+	var results string
+	buildinfo, ok = debug.ReadBuildInfo()
+	if ok {
+		// We have build info, display it.
+		goversion := buildinfo.GoVersion
+
+		var bs debug.BuildSetting
+		for _, bs = range buildinfo.Settings {
+			if bs.Key == "vcs.revision" || bs.Key == "vcs.time" {
+				results += bs.Value + " "
+			}
+		}
+		return goversion, results
+	}
+	return "", ""
+}
+
+func GetModules() map[string]string {
+	var buildinfo *debug.BuildInfo
+	var ok bool
+	var results map[string]string = make(map[string]string)
+	buildinfo, ok = debug.ReadBuildInfo()
+	if ok {
+		// We have Module info, return it.
+		for _, mod := range buildinfo.Deps {
+			results[mod.Path] = mod.Version
+		}
+	}
+	return results
+}