Prefix version with label

pull/71/head
Miguel Mota 4 years ago
parent 34111fc6ea
commit f82c113ed6

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

@ -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

Loading…
Cancel
Save