Makefile 1.52 KB
Newer Older
kzkzzzz's avatar
kzkzzzz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
project=demo
API_PROTO_FILES=$(shell find api/$(project) -name *.proto)


# go-micro仓库https://github.com/asim/go-micro
# 安装命令行工具
.PHONY: init
init:
	go env -w GO111MODULE=on
	go env -w GOPROXY=https://goproxy.cn,direct
	go get -u google.golang.org/protobuf/proto
	go install github.com/golang/protobuf/protoc-gen-go@latest
	go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
	go install github.com/asim/go-micro/cmd/protoc-gen-micro/v4@latest
	go install github.com/favadi/protoc-go-inject-tag@latest
	go install github.com/kzkzzzz/dbtogo@main
	go install github.com/go-micro/cli/cmd/go-micro@latest
	go install github.com/cosmtrek/air@latest


.PHONY: gen
gen:
	@bash script/gen.sh $(project)
	@make api project=$(project)


# 根据 api/服务/service里面的proto文件 生成, mac和linux分别移除omitempty标签
# protoc-go-inject-tag用于自定义json等tag
.PHONY: api
api:
	protoc --proto_path=./api/$(project) \
		   --go_out=:./api/$(project) --go_opt=paths=source_relative \
		   --micro_out=:./api/$(project) --micro_opt=paths=source_relative \
		   $(API_PROTO_FILES)
	protoc-go-inject-tag -input=api/$(project)/*.pb.go
	@grep -rl 'omitempty' api/$(project)/*.pb.go | xargs -I {} sed -i "s#,omitempty##g" {} || true
	@grep -rl 'omitempty' api/$(project)/*.pb.go | xargs -I {} sed -i '' "s#,omitempty##g" {} || true


.PHONY: tidy
tidy:
	@go mod download
	@go mod tidy

.PHONY: run
run:
	@cd service/$(project) && go-micro run

.PHONY: build
build:
	@cd service/$(project) && go build -v -o ./bin/server .