Skip to content

Commit

Permalink
chore(binary): support LDFLAGS by goreleaser
Browse files Browse the repository at this point in the history
fix #713
  • Loading branch information
appleboy committed Feb 27, 2023
1 parent 9b67d16 commit 5af2379
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TARGETS ?= linux darwin windows
ARCHS ?= amd64
GOFILES := $(shell find . -name "*.go" -type f)
TAGS ?= sqlite
LDFLAGS ?= -X 'main.Version=$(VERSION)'
LDFLAGS ?= -X main.version=$(VERSION) -X main.commit=$(COMMIT)

PROTOC_GEN_GO=v1.28
PROTOC_GEN_GO_GRPC=v1.2
Expand All @@ -27,6 +27,8 @@ else
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
endif

COMMIT ?= $(shell git rev-parse --short HEAD)

.PHONY: all
all: build

Expand Down
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func main() {
flag.Usage = usage
flag.Parse()

router.SetVersion(Version)
router.SetVersion(version)
router.SetCommit(commit)

// Show version and exit
if showVersion {
Expand Down Expand Up @@ -394,7 +395,10 @@ func main() {
}

// Version control for notify.
var Version = "No Version Provided"
var (
version = "No Version Provided"
commit = "No Commit Provided"
)

var usageStr = `
________ .__
Expand Down
13 changes: 11 additions & 2 deletions router/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,31 @@ import (
"github.com/gin-gonic/gin"
)

var version string
var (
version string
commit string
)

// SetVersion for setup version string.
func SetVersion(ver string) {
version = ver
}

// SetCommit for setup commit string.
func SetCommit(ver string) {
commit = ver
}

// GetVersion for get current version.
func GetVersion() string {
return version
}

// PrintGoRushVersion provide print server engine
func PrintGoRushVersion() {
fmt.Printf(`GoRush %s, Compiler: %s %s, Copyright (C) 2019 Bo-Yi Wu, Inc.`,
fmt.Printf(`GoRush %s, Commit: %s, Compiler: %s %s, Copyright (C) 2023 Bo-Yi Wu, Inc.`,
version,
commit,
runtime.Compiler,
runtime.Version())
fmt.Println()
Expand Down

0 comments on commit 5af2379

Please sign in to comment.