-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc95eb4
commit 3d32fef
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package gdk_test | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/researchlab/gdk" | ||
) | ||
|
||
// build binary by makefile, command | ||
// make default -f version.Makefile | ||
// ExampleVersion version examples | ||
func ExampleVersion() { | ||
v := gdk.Version() | ||
// version by console cmd | ||
args := os.Args | ||
if len(args) >= 2 && args[1] == "version" { | ||
fmt.Println(v.String()) | ||
return | ||
} | ||
// version by http request | ||
http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprint(w, v) | ||
}) | ||
http.ListenAndServe(":8082", nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.PHONY: list vet fmt default clean | ||
all: list vet fmt default clean | ||
# ###### 只需要设置下面两个参数, 其它都不需要修改 | ||
BINARY="binary" | ||
VERSION=0.0.1 | ||
# ##### | ||
BUILD=`date +%F` | ||
SHELL := /bin/bash | ||
BASEDIR = $(shell pwd) | ||
|
||
# build with verison infos | ||
versionDir="github.com/researchlab/gdk" | ||
gitTag=$(shell if [ "`git describe --tags --abbrev=0 2>/dev/null`" != "" ];then git describe --tags --abbrev=0; else git log --pretty=format:'%h' -n 1; fi) # format:'%H' 完整的commit id | ||
gitBranch=$(shell git rev-parse --abbrev-ref HEAD) | ||
buildDate=$(shell TZ=Asia/Shanghai date +%FT%T%z) | ||
gitCommit=$(shell git rev-parse --short HEAD) # 去掉--short 就是完整的commit-id | ||
gitTreeState=$(shell if git status|grep -q 'clean';then echo clean; else echo dirty; fi) | ||
|
||
ldflags="-s -w -X ${versionDir}.gitTag=${gitTag} -X ${versionDir}.buildDate=${buildDate} -X ${versionDir}.gitCommit=${gitCommit} -X ${versionDir}.gitTreeState=${gitTreeState} -X ${versionDir}.version=${VERSION} -X ${versionDir}.gitBranch=${gitBranch}" | ||
|
||
|
||
PACKAGES=`go list ./... | grep -v /vendor/` | ||
VETPACKAGES=`go list ./... | grep -v /vendor/ | grep -v /examples/` | ||
GOFILES=`find . -name "*.go" -type f -not -path "./vendor/*"` | ||
|
||
default: | ||
@echo "build the ${BINARY}" | ||
@GOOS=linux GOARCH=amd64 go build -ldflags ${ldflags} -o build/${BINARY}.linux -tags=jsoniter | ||
@GOOS=darwin GOARCH=arm64 go build -ldflags ${ldflags} -o build/${BINARY}.mac -tags=jsoniter | ||
@echo "build done." | ||
|
||
list: | ||
@echo ${PACKAGES} | ||
@echo ${VETPACKAGES} | ||
@echo ${GOFILES} | ||
|
||
fmt: | ||
@echo "fmt the project" | ||
@gofmt -s -w ${GOFILES} | ||
|
||
vet: | ||
@echo "check the project codes." | ||
@go vet $(VETPACKAGES) | ||
@echo "check done." | ||
|
||
|
||
clean: | ||
@rm -rf build/* | ||
|