From f82c113ed6496b63e3f5c9a6c25524d9072d1c0f Mon Sep 17 00:00:00 2001 From: Miguel Mota Date: Tue, 25 Aug 2020 00:14:24 -0700 Subject: [PATCH] Prefix version with label --- .rpm/cointop.spec | 2 +- cointop/version.go | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.rpm/cointop.spec b/.rpm/cointop.spec index 325751d..b9f334e 100644 --- a/.rpm/cointop.spec +++ b/.rpm/cointop.spec @@ -24,7 +24,7 @@ mkdir -p ./_build/src/github.com/miguelmota ln -s $(pwd) ./_build/src/github.com/miguelmota/%{name} export GOPATH=$(pwd)/_build:%{gopath} -GO111MODULE=off go build -ldflags="-linkmode=external -compressdwarf=false -X github.com/miguelmota/cointop/cointop.version=v%{version}" -o x . +GO111MODULE=off go build -ldflags="-linkmode=external -compressdwarf=false -X github.com/miguelmota/cointop/cointop.version=%{version}" -o x . %install install -d %{buildroot}%{_bindir} diff --git a/cointop/version.go b/cointop/version.go index a7c406c..cf4c8c7 100644 --- a/cointop/version.go +++ b/cointop/version.go @@ -3,6 +3,7 @@ package cointop import ( "fmt" "runtime/debug" + "strings" ) // version is the cointop version which will be populated by ldflags @@ -15,15 +16,18 @@ func (ct *Cointop) Version() string { // Version returns cointop version func Version() string { + ver := "(devel)" if version != "" { - return version + ver = version + } else if buildInfo, ok := debug.ReadBuildInfo(); ok { + ver = buildInfo.Main.Version } - if buildInfo, ok := debug.ReadBuildInfo(); ok { - return buildInfo.Main.Version + if !strings.HasPrefix(ver, "v") { + ver = fmt.Sprintf("v%s", ver) } - return "(devel)" + return ver } // PrintVersion prints the version