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} ln -s $(pwd) ./_build/src/github.com/miguelmota/%{name}
export GOPATH=$(pwd)/_build:%{gopath} 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
install -d %{buildroot}%{_bindir} install -d %{buildroot}%{_bindir}

@ -3,6 +3,7 @@ package cointop
import ( import (
"fmt" "fmt"
"runtime/debug" "runtime/debug"
"strings"
) )
// version is the cointop version which will be populated by ldflags // version is the cointop version which will be populated by ldflags
@ -15,15 +16,18 @@ func (ct *Cointop) Version() string {
// Version returns cointop version // Version returns cointop version
func Version() string { func Version() string {
ver := "(devel)"
if version != "" { if version != "" {
return version ver = version
} else if buildInfo, ok := debug.ReadBuildInfo(); ok {
ver = buildInfo.Main.Version
} }
if buildInfo, ok := debug.ReadBuildInfo(); ok { if !strings.HasPrefix(ver, "v") {
return buildInfo.Main.Version ver = fmt.Sprintf("v%s", ver)
} }
return "(devel)" return ver
} }
// PrintVersion prints the version // PrintVersion prints the version

Loading…
Cancel
Save