新建Makefile,添加示例代码如下,
bash
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
bash
make dev
Linux
bash
make