chore(binary): support LDFLAGS by goreleaser
fix https://github.com/appleboy/gorush/issues/713
This commit is contained in:
parent
9b67d16e17
commit
5af237945e
4
Makefile
4
Makefile
|
@ -10,7 +10,7 @@ TARGETS ?= linux darwin windows
|
||||||
ARCHS ?= amd64
|
ARCHS ?= amd64
|
||||||
GOFILES := $(shell find . -name "*.go" -type f)
|
GOFILES := $(shell find . -name "*.go" -type f)
|
||||||
TAGS ?= sqlite
|
TAGS ?= sqlite
|
||||||
LDFLAGS ?= -X 'main.Version=$(VERSION)'
|
LDFLAGS ?= -X main.version=$(VERSION) -X main.commit=$(COMMIT)
|
||||||
|
|
||||||
PROTOC_GEN_GO=v1.28
|
PROTOC_GEN_GO=v1.28
|
||||||
PROTOC_GEN_GO_GRPC=v1.2
|
PROTOC_GEN_GO_GRPC=v1.2
|
||||||
|
@ -27,6 +27,8 @@ else
|
||||||
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
|
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
COMMIT ?= $(shell git rev-parse --short HEAD)
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
|
|
8
main.go
8
main.go
|
@ -82,7 +82,8 @@ func main() {
|
||||||
flag.Usage = usage
|
flag.Usage = usage
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
router.SetVersion(Version)
|
router.SetVersion(version)
|
||||||
|
router.SetCommit(commit)
|
||||||
|
|
||||||
// Show version and exit
|
// Show version and exit
|
||||||
if showVersion {
|
if showVersion {
|
||||||
|
@ -394,7 +395,10 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version control for notify.
|
// Version control for notify.
|
||||||
var Version = "No Version Provided"
|
var (
|
||||||
|
version = "No Version Provided"
|
||||||
|
commit = "No Commit Provided"
|
||||||
|
)
|
||||||
|
|
||||||
var usageStr = `
|
var usageStr = `
|
||||||
________ .__
|
________ .__
|
||||||
|
|
|
@ -7,13 +7,21 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version string
|
var (
|
||||||
|
version string
|
||||||
|
commit string
|
||||||
|
)
|
||||||
|
|
||||||
// SetVersion for setup version string.
|
// SetVersion for setup version string.
|
||||||
func SetVersion(ver string) {
|
func SetVersion(ver string) {
|
||||||
version = ver
|
version = ver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetCommit for setup commit string.
|
||||||
|
func SetCommit(ver string) {
|
||||||
|
commit = ver
|
||||||
|
}
|
||||||
|
|
||||||
// GetVersion for get current version.
|
// GetVersion for get current version.
|
||||||
func GetVersion() string {
|
func GetVersion() string {
|
||||||
return version
|
return version
|
||||||
|
@ -21,8 +29,9 @@ func GetVersion() string {
|
||||||
|
|
||||||
// PrintGoRushVersion provide print server engine
|
// PrintGoRushVersion provide print server engine
|
||||||
func PrintGoRushVersion() {
|
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,
|
version,
|
||||||
|
commit,
|
||||||
runtime.Compiler,
|
runtime.Compiler,
|
||||||
runtime.Version())
|
runtime.Version())
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
Loading…
Reference in New Issue