新建Makefile,添加示例代码如下,
GO ?= go
BINARY_NAME=service-control-center
DEV_OUTPUT:=$(CURDIR)/$(BINARY_NAME)-dev
DEPLOY_DIR:=$(CURDIR)
DEPLOY_OUTPUT:=$(DEPLOY_DIR)/$(BINARY_NAME)
UNAME_S=$(shell uname -s)
BUILD_ENV=GOTRACEBACK=all
BUILD_FLAG=--ldflags "-X main.Version=`date +.%Y%m%d.%H%M%S` -X main.Hostname=`hostname` -X main.BuildType=$@"
export GO111MODULE=on
ifeq ($(UNAME_S), Linux)
MD5_TOOL:=md5sum
endif
ifeq ($(UNAME_S), Darwin)
MD5_TOOL:=md5 -r
endif
all: dev
dev:
env $(BUILD_ENV) $(GO) build -race $(BUILD_FLAG) -o $(DEV_OUTPUT)
release:
env GOOS=linux GOARCH=amd64 $(BUILD_ENV) $(GO) build $(BUILD_FLAG) -o $(DEPLOY_OUTPUT) && find . -type f -not -path '*/\.*' -exec $(MD5_TOOL) {} + > $(DEPLOY_DIR)/md5.release
clean:
rm -rf $(BINARY_NAME)-dev
rm -rf $(BINARY_NAME)
rm -rf *.test
rm -rf controllers/*.test
test:
go test -v -cover $(go list ./... | grep -v /test)
coverage:
go test -v -cover $(go list ./... | grep -v /test) > test.result
FORCE:
适用于在Mac 下开发dev,在linux下部署,示例
Mac
make dev
Linux
make
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » GO语言工程构建示例-mac和linux适用
发表评论 取消回复