APP = user
MAIN = user.go
OUTPUT = bin/$(APP)
PROTO_DIR = apps/user/rpc
API_DIR = api
API_OUTPUT = apps/user/api
RPC_OUTPUT = apps/user/rpc
BIN_DIR = bin
API_CONFIG = apps/user/api/etc/user.yaml
RPC_CONFIG = apps/user/rpc/etc/user.yaml
.PHONY: all
all: build
.PHONY: rpc-run
rpc-run:
@echo "Running RPC service..."
$(RPC_OUTPUT)/$(APP).go -f $(RPC_CONFIG)
.PHONY: api-run
api-run:
@echo "Running API service..."
$(API_OUTPUT)/$(APP).go -f $(API_CONFIG)
.PHONY: build
build: build-api build-rpc
@echo "Build complete!"
.PHONY: build-api
build-api:
@echo "Building API service..."
go build -o $(BIN_DIR)/api_service $(API_OUTPUT)/$(APP).go
.PHONY: build-rpc
build-rpc:
@echo "Building RPC service..."
go build -o $(BIN_DIR)/rpc_service $(RPC_OUTPUT)/$(APP).go
.PHONY: run
run: run-rpc run-api
.PHONY: run-api
run-api:
@echo "Running API service..."
$(BIN_DIR)/api_service -f $(API_CONFIG)
.PHONY: run-rpc
run-rpc:
@echo "Running RPC service..."
$(BIN_DIR)/rpc_service -f $(RPC_CONFIG)
.PHONY: proto
proto:
@echo "Generating gRPC and Go Zero proto files..."
cd $(PROTO_DIR) && goctl rpc protoc user.proto --go_out=. --go-grpc_out=. --zrpc_out=. --style=goZero
.PHONY: api
api:
@echo "Generating Go Zero API files..."
cd apps && goctl api go -api user/api/user.api -dir user/api -style gozero
.PHONY: clean
clean:
@echo "Cleaning up..."
rm -rf $(OUTPUT)
.PHONY: deps
deps:
@echo "Updating dependencies..."
go mod tidy
.PHONY: fmt
fmt:
@echo "Formatting code..."
go fmt ./...
.PHONY: test
test:
@echo "Running tests..."
go test ./... -v