Skip to content

Commit

Permalink
Add platform information to --version (#117)
Browse files Browse the repository at this point in the history
* Add platform information to --version
  • Loading branch information
tal66 authored Jul 26, 2022
1 parent 8180b93 commit 0fc3b33
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
GIT_HASH := $(shell git rev-parse --verify HEAD)
GIT_TAG := $(shell git describe --tags --exact-match --abbrev=0 2>/dev/null || echo "")
BUILD_TIME ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
PLATFORM := $(OS)/$(ARCH)

ifdef GIT_TAG
VERSION := $(GIT_TAG)/$(GIT_HASH)
Expand All @@ -19,7 +20,8 @@ endif

LDFLAGS := -X main.version=$(VERSION) \
-X main.goVersion=$(shell go version | cut -d " " -f 3) \
-X main.buildTime=$(BUILD_TIME)
-X main.buildTime=$(BUILD_TIME) \
-X 'main.platform=$(PLATFORM)'

all: $(TARGET)

Expand Down
5 changes: 4 additions & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,26 @@ type Version struct {
Version string
GoVersion string
BuildTime string
Platform string
}

var (
v Version
version string
goVersion string
buildTime string
platform string
)

func init() {
v = Version{
Version: version,
GoVersion: goVersion,
BuildTime: buildTime,
Platform: platform,
}
}

func (ver Version) String() string {
return fmt.Sprintf("\ngit hash: %s\nGo version: %s\nBuild time: %s", v.Version, v.GoVersion, v.BuildTime)
return fmt.Sprintf("\ngit hash: %s\nGo version: %s\nBuild time: %s\nPlatform: %s", v.Version, v.GoVersion, v.BuildTime, v.Platform)
}

0 comments on commit 0fc3b33

Please sign in to comment.