123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 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
- }
|