github.com/Go-To-Byte/DouSheng/user_center@v0.0.0-20230524130918-ad531c1a3f6a/Makefile (about) 1 PROJECT_NAME=user_center 2 MAIN_FILE=main.go 3 PKG := "github.com/Go-To-Byte/DouSheng/$(PROJECT_NAME)" 4 MOD_DIR := $(shell go env GOMODCACHE) 5 PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/) 6 GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/ | grep -v _test.go) 7 8 .PHONY: all dep lint vet test test-coverage build clean 9 10 BUILD_BRANCH := $(shell git rev-parse --abbrev-ref HEAD) 11 BUILD_COMMIT := ${shell git rev-parse HEAD} 12 BUILD_TIME := ${shell date '+%Y-%m-%d %H:%M:%S'} 13 BUILD_GO_VERSION := $(shell go version | grep -o 'go[0-9].[0-9].*') 14 VERSION_PATH := "${PKG}/version" 15 16 all: build 17 18 dep: ## Get the dependencies 19 @go mod tidy 20 21 lint: ## Lint Golang files 22 @golint -set_exit_status ${PKG_LIST} 23 24 vet: ## Run go vet 25 @go vet ${PKG_LIST} 26 27 test: ## Run unittests 28 @go test -short ${PKG_LIST} 29 30 test-coverage: ## Run tests with coverage 31 @go test -short -coverprofile cover.out -covermode=atomic ${PKG_LIST} 32 @cat cover.out >> coverage.txt 33 34 build: dep ## Build the binary file 35 @go build -ldflags "-s -w" -ldflags "-X '${VERSION_PATH}.GIT_BRANCH=${BUILD_BRANCH}' -X '${VERSION_PATH}.GIT_COMMIT=${BUILD_COMMIT}' -X '${VERSION_PATH}.BUILD_TIME=${BUILD_TIME}' -X '${VERSION_PATH}.GO_VERSION=${BUILD_GO_VERSION}'" -o dist/dousheng-api $(MAIN_FILE) 36 37 linux: dep ## Build the binary file 38 @GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -ldflags "-X '${VERSION_PATH}.GIT_BRANCH=${BUILD_BRANCH}' -X '${VERSION_PATH}.GIT_COMMIT=${BUILD_COMMIT}' -X '${VERSION_PATH}.BUILD_TIME=${BUILD_TIME}' -X '${VERSION_PATH}.GO_VERSION=${BUILD_GO_VERSION}'" -o dist/dousheng-api $(MAIN_FILE) 39 40 install: ## Install depence go package 41 @go install google.golang.org/protobuf/cmd/protoc-gen-go@latest 42 @go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest 43 @go install github.com/favadi/protoc-go-inject-tag@latest 44 45 gen: ## generate protobuf file 46 # @protoc -I=. -I=common/pb --go_out=. --go_opt=module=${PKG} --go-grpc_out=. --go-grpc_opt=module=${PKG} apps/*/pb/*.proto common/pb/*.proto 47 @protoc -I=. --go_out=. --go_opt=module=${PKG} --go-grpc_out=. --go-grpc_opt=module=${PKG} apps/*/pb/*.proto 48 @go fmt ./... 49 @protoc-go-inject-tag -input=apps/*/*.pb.go 50 # @protoc-go-inject-tag -input=common/*.pb.go 51 52 init: dep ## Initial project 53 @go run $(MAIN_FILE) init 54 55 run: # Run Develop server 56 @go run $(MAIN_FILE) start -f etc/config.toml 57 58 clean: ## Remove previous build 59 @rm -f dist/* 60 61 help: ## Display this help screen 62 @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'