# 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/permission" .PHONY: test test: # 進行測試 go test -v --cover ./... .PHONY: fmt fmt: # 格式優化 $(GOFMT) -w $(GOFILES) goimports -w ./ .PHONY: gen-rpc gen-rpc: # 建立 rpc code goctl rpc protoc ./generate/protobuf/service.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 service.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" .PHONY: gen-my-sql-model-up gen-my-sql-model: # 建立 rpc 資料庫 goctl model mysql ddl -c no -s ./generate/database/mysql/20240816014305_create_permission_table.up.sql --style $(GO_ZERO_STYLE) -d ./internal/model -i '' goctl model mysql ddl -c no -s ./generate/database/mysql/20240819013052_create_roles_table.up.sql --style $(GO_ZERO_STYLE) -d ./internal/model -i '' goctl model mysql ddl -c no -s ./generate/database/mysql/20240819022436_create_user_role_table.up.sql --style $(GO_ZERO_STYLE) -d ./internal/model -i '' goctl model mysql ddl -c no -s ./generate/database/mysql/20240819090248_create_role_permission_table.up.sql --style $(GO_ZERO_STYLE) -d ./internal/model -i '' @echo "Generate mysql model files successfully" .PHONY: mock-gen mock-gen: # 建立 mock 資料 mockgen -source=./internal/model/permission_model.go -destination=./internal/mock/model/permission_model.go -package=mock mockgen -source=./internal/model/permission_model_gen.go -destination=./internal/mock/model/permission_model_gen.go -package=mock mockgen -source=./internal/model/role_model.go -destination=./internal/mock/model/role_model.go -package=mock mockgen -source=./internal/model/role_model_gen.go -destination=./internal/mock/model/role_model_gen.go -package=mock mockgen -source=./internal/model/role_permission_model.go -destination=./internal/mock/model/role_permission_model.go -package=mock mockgen -source=./internal/model/role_permission_model_gen.go -destination=./internal/mock/model/role_permission_model_gen.go -package=mock mockgen -source=./internal/model/user_role_model.go -destination=./internal/mock/model/user_role_model.go -package=mock mockgen -source=./internal/model/user_role_model_gen.go -destination=./internal/mock/model/user_role_model_gen.go -package=mock @echo "Generate mock files successfully" .PHONY: migrate-database migrate-database: migrate -source file://generate/database/mysql -database 'mysql://root:yytt@tcp(127.0.0.1:3306)/digimon_member' up migrate -source file://generate/database/seeders -database 'mysql://root:yytt@tcp(127.0.0.1:3306)/digimon_member' up