118 lines
3.2 KiB
Makefile
118 lines
3.2 KiB
Makefile
# Go parameters
|
|
GOCMD=go
|
|
GOBUILD=$(GOCMD) build -trimpath -ldflags="-s -w"
|
|
GOTEST=$(GOCMD) test
|
|
GODOWNLOAD=$(GOCMD) mod download
|
|
BINARY_NAME=datarush
|
|
MIGRATE_BINARY_NAME=datarush-migrate
|
|
BINARY_DIR=bin
|
|
|
|
# Protobuf parameters
|
|
PROTOC=protoc
|
|
PROTO_DIR=api/proto
|
|
PROTO_FILE=$(PROTO_DIR)/auth.proto $(PROTO_DIR)/competition.proto $(PROTO_DIR)/results.proto $(PROTO_DIR)/review.proto $(PROTO_DIR)/submission.proto $(PROTO_DIR)/task.proto $(PROTO_DIR)/user.proto
|
|
PROTO_OUT=.
|
|
|
|
.PHONY: install i generate gen generate-gw test build run migrate lint fmt format clean help codegen examples
|
|
|
|
install:
|
|
$(GODOWNLOAD)
|
|
|
|
i: install
|
|
|
|
generate:
|
|
$(PROTOC) --version || (echo "protoc not found, install protoc"; exit 1)
|
|
$(PROTOC) --go_out=$(PROTO_OUT) --go-grpc_out=$(PROTO_OUT) \
|
|
$(PROTO_FILE)
|
|
|
|
gen: generate
|
|
|
|
generate-gw:
|
|
$(PROTOC) --version || (echo "protoc not found, install protoc"; exit 1)
|
|
$(PROTOC) --grpc-gateway_out=$(PROTO_OUT) --grpc-gateway_opt generate_unbound_methods=true \
|
|
$(PROTO_FILE)
|
|
|
|
test:
|
|
$(GOTEST) ./...
|
|
|
|
build:
|
|
$(GOBUILD) -o ./$(BINARY_DIR)/$(BINARY_NAME) ./cmd/server
|
|
chmod +x ./$(BINARY_DIR)/$(BINARY_NAME)
|
|
|
|
build-migrate:
|
|
$(GOBUILD) -o ./$(BINARY_DIR)/$(MIGRATE_BINARY_NAME) ./cmd/migrate
|
|
chmod +x ./$(BINARY_DIR)/$(MIGRATE_BINARY_NAME)
|
|
|
|
run: build
|
|
./$(BINARY_DIR)/$(BINARY_NAME)
|
|
|
|
migrate: build-migrate
|
|
@cmd=$(word 2,$(MAKECMDGOALS)); \
|
|
if [ -z "$$cmd" ]; then \
|
|
echo "Usage: make migrate <command>"; \
|
|
exit 1; \
|
|
fi; \
|
|
./$(BINARY_DIR)/$(MIGRATE_BINARY_NAME) -cmd $$cmd
|
|
|
|
lint:
|
|
golangci-lint run -c .golangci.yaml ./...
|
|
|
|
fmt:
|
|
golangci-lint fmt -c .golangci.yaml ./...
|
|
|
|
format: fmt
|
|
|
|
clean:
|
|
rm -rf bin/*
|
|
|
|
codegen:
|
|
@if [ -z "$(SERVICE)" ]; then \
|
|
echo "Usage: make codegen SERVICE=<service-name>"; \
|
|
echo "Example: make codegen SERVICE=auth"; \
|
|
exit 1; \
|
|
fi
|
|
$(GOBUILD) -o ./$(BINARY_DIR)/codegen ./cmd/codegen
|
|
./$(BINARY_DIR)/codegen $(SERVICE) ./
|
|
|
|
examples:
|
|
@echo "📖 Datarush-Go Integration Examples"
|
|
@echo ""
|
|
@echo "Files:"
|
|
@echo " - SQL_BUILDER_ADVANCED.md - Детальные примеры SQL Builder"
|
|
@echo " - SQL_BUILDER_CODEGEN.md - Документация Codegen"
|
|
@echo " - SQL_EXAMPLES.sql - SQL схемы и примеры"
|
|
@echo " - INTEGRATION_EXAMPLES.sh - Интеграционные примеры"
|
|
@echo ""
|
|
@echo "Быстрый старт:"
|
|
@echo " 1. make codegen SERVICE=payment"
|
|
@echo " 2. Edit internal/payment/repository/postgres/repo.go"
|
|
@echo " 3. Edit internal/payment/service/service.go"
|
|
@echo " 4. go test ./internal/payment/..."
|
|
@echo ""
|
|
@cat INTEGRATION_EXAMPLES.sh
|
|
|
|
|
|
help:
|
|
@echo "Available commands:"
|
|
@echo " install - Install all deps using go mod download"
|
|
@echo " i"
|
|
@echo " generate - Generate gRPC code"
|
|
@echo " gen"
|
|
@echo " protoc"
|
|
@echo " codegen - Generate service template"
|
|
@echo " Usage: make codegen SERVICE=<name>"
|
|
@echo " examples - Show integration examples"
|
|
@echo " test - Run tests"
|
|
@echo " build - Build the binary"
|
|
@echo " run - Run the application"
|
|
@echo " lint - Run golangci-lint linter"
|
|
@echo " format - Run golangci-lint formatter"
|
|
@echo " fmt"
|
|
@echo " clean - Clean build artifacts"
|
|
|
|
|
|
.DEFAULT_GOAL := help
|
|
|
|
%:
|
|
@:
|