diff options
author | Miguel Mota <miguelmota2@gmail.com> | 2020-08-04 22:27:08 -0700 |
---|---|---|
committer | Miguel Mota <miguelmota2@gmail.com> | 2020-08-04 22:42:17 -0700 |
commit | 523c43025a413f8cfe667d940f5fba5d8dbc8bf3 (patch) | |
tree | dce1e127403295f831b310c20e6bac1a6e087b2f | |
parent | 1cd4c3c2953f8e7ea474bfe77046065cb51293a6 (diff) |
Read version from runtime build info if availablev1.5.0
-rw-r--r-- | cointop/version.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/cointop/version.go b/cointop/version.go index e9cad6a..51f7b54 100644 --- a/cointop/version.go +++ b/cointop/version.go @@ -3,18 +3,27 @@ package cointop import ( "fmt" "os" + "runtime/debug" ) // version is the cointop version which will be populated by ldflags -var version = "dev" +var version string = "(unknown)" // Version returns the cointop version func (ct *Cointop) Version() string { - return version + return Version() } // Version returns cointop version func Version() string { + if version != "(unknown)" { + return version + } + + if buildInfo, ok := debug.ReadBuildInfo(); ok { + return buildInfo.Main.Version + } + return version } |