65 lines
1.9 KiB
Makefile
65 lines
1.9 KiB
Makefile
GO_CTL_NAME=goctl
|
|
|
|
# go-zero 生成風格
|
|
GO_ZERO_STYLE=go_zero
|
|
|
|
GO ?= go
|
|
GOFMT ?= gofmt "-s"
|
|
GOFILES := $(shell find . -name "*.go")
|
|
LDFLAGS := -s -w
|
|
VERSION="v1.0.1"
|
|
DOCKER_REPO="igs170911/feed"
|
|
|
|
.PHONY: test
|
|
test: # 進行測試
|
|
go test -v --cover ./...
|
|
|
|
.PHONY: fmt
|
|
fmt: # 格式優化
|
|
$(GOFMT) -w $(GOFILES)
|
|
goimports -w ./
|
|
golangci-lint run
|
|
|
|
.PHONY: gen-rpc
|
|
gen-rpc: # 建立 rpc code
|
|
$(GO_CTL_NAME) rpc protoc ./generate/protobuf/trade.proto -m --style=$(GO_ZERO_STYLE) --go_out=./gen_result/pb --go-grpc_out=./gen_result/pb --zrpc_out=.
|
|
go mod tidy
|
|
@echo "Generate core-api files successfully"
|
|
|
|
.PHONY: gen-clean
|
|
gen-clean: # 建立 rpc code
|
|
rm -rf ./client
|
|
rm -rf ./etc
|
|
rm -rf ./gen_result
|
|
rm -rf ./internal
|
|
rm -rf go.mod
|
|
rm -rf go.sum
|
|
rm -rf order.go
|
|
@echo "Generate core-api files successfully"
|
|
|
|
.PHONY: run-docker
|
|
run-docker: # 建立 rpc code
|
|
docker run --platform=linux/arm64/v8 -p 8080:8080 $(DOCKER_REPO):$(VERSION)
|
|
|
|
.PHONY: build-docker
|
|
build-docker:
|
|
cp ./build/Dockerfile Dockerfile
|
|
docker buildx build -t $(DOCKER_REPO):$(VERSION) --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/ed_25519)" .
|
|
rm -rf Dockerfile
|
|
@echo "Generate core-api files successfully"
|
|
|
|
gen-mongo-model: # 建立 rpc 資料庫
|
|
# 只產生 Model 剩下的要自己撰寫,連欄位名稱也是
|
|
goctl model mongo -t order --dir ./internal/model/mongo --style $(GO_ZERO_STYLE)
|
|
@echo "Generate mongo model files successfully"
|
|
|
|
.PHONY: mock-gen
|
|
mock-gen: # 建立 mock 資料
|
|
mockgen -source=./internal/model/mongo/order_model_gen.go -destination=./internal/mock/model/order_model_gen.go -package=mock
|
|
mockgen -source=./internal/model/mongo/order_model.go -destination=./internal/mock/model/order_model.go -package=mock
|
|
@echo "Generate mock files successfully"
|
|
|
|
.PHONY: migrate-database
|
|
migrate-database:
|
|
migrate -source file://generate/database/mongodb -database 'mongodb://127.0.0.1:27017/digimon_order' up
|