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 .