123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package ircclient
- import (
- "fmt"
- "runtime/debug"
- )
- // Get build version from BuildInfo
- 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()
- }
- }
- // Get Go version, arch, and OS. Get git commit hash.
- func GetVersion() (goversion string, gitcommit string, arch string, goos string) {
- var buildinfo *debug.BuildInfo
- var ok bool
- var results string
- var garch, gos 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 + " "
- }
- if bs.Key == "GOARCH" {
- garch = bs.Value
- }
- if bs.Key == "GOOS" {
- gos = bs.Value
- }
- }
- return goversion, results, garch, gos
- }
- return "", "", "", ""
- }
- // Get modules information
- //
- // Return map of module name and version.
- 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
- }
|