Files
MyGoServer/Makefile

147 lines
4.4 KiB
Makefile

# MyGoServer Makefile
# Удобные команды для разработки и тестирования
.PHONY: help build test test-coverage test-race fmt vet clean docker-up docker-down
# Default target
help:
@echo "🚀 MyGoServer Development Commands:"
@echo ""
@echo "📦 Build Commands:"
@echo " build - Build the application"
@echo " build-clean - Clean build and rebuild"
@echo ""
@echo "🧪 Test Commands:"
@echo " test - Run all tests"
@echo " test-unit - Run unit tests only"
@echo " test-coverage - Run tests with coverage report"
@echo " test-race - Run tests with race detector"
@echo " test-watch - Run tests in watch mode"
@echo ""
@echo "🔧 Code Quality:"
@echo " fmt - Format all Go code"
@echo " vet - Run static analysis"
@echo " lint - Run linting (if golangci-lint installed)"
@echo ""
@echo "🐳 Docker Commands:"
@echo " docker-up - Start application with Docker"
@echo " docker-down - Stop Docker containers"
@echo " docker-build - Build Docker image"
@echo ""
@echo "🧹 Cleanup:"
@echo " clean - Clean build artifacts"
@echo ""
# Build commands
build: generate-docs
@echo "🏗️ Building application..."
go build -o apiserver ./cmd/apiserver
@echo "✅ Build completed: apiserver"
generate-docs:
@echo "📖 Generating Swagger documentation..."
swag init -g cmd/apiserver/main.go -o internal/apiserver/docs
@echo "✅ Swagger documentation generated"
build-clean: clean build
# Test commands
test:
@echo "🧪 Running all tests..."
./scripts/test.sh
test-unit:
@echo "🧪 Running unit tests..."
go test -v ./internal/apiserver/...
test-coverage:
@echo "📊 Running tests with coverage..."
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "📊 Coverage report: coverage.html"
test-race:
@echo "🏁 Running tests with race detector..."
go test -race ./...
test-watch:
@echo "👀 Running tests in watch mode..."
@which gotest > /dev/null || (echo "Installing gotest-watcher..." && go install github.com/bitfield/gotest@latest)
gotest -w ./...
# Code quality
fmt:
@echo "🎨 Formatting code..."
go fmt ./...
@echo "✅ Code formatted"
vet:
@echo "🔍 Running static analysis..."
go vet ./...
@echo "✅ Static analysis completed"
lint:
@echo "🧹 Running linter..."
@which golangci-lint > /dev/null || (echo "Installing golangci-lint..." && go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest)
golangci-lint run
@echo "✅ Linting completed"
# Docker commands
docker-up:
@echo "🐳 Starting application with Docker..."
docker-compose -f build/docker-compose.yml up -d
@echo "🚀 Application started on http://localhost:8080"
@echo "📖 Swagger UI: http://localhost:8080/swagger/"
docker-down:
@echo "🛑 Stopping Docker containers..."
docker-compose -f build/docker-compose.yml down
docker-build:
@echo "🔨 Building Docker image..."
docker build -f build/Dockerfile -t mygoserver:latest .
# Cleanup
clean:
@echo "🧹 Cleaning build artifacts..."
rm -f apiserver coverage.out coverage.html
rm -rf build/bin/
docker-compose -f build/docker-compose.yml down -v 2>/dev/null || true
@echo "✅ Cleanup completed"
# Development helpers
dev: build
@echo "🚀 Starting development server..."
./apiserver
debug: build
@echo "🐛 Starting debug server..."
dlv --listen=:2345 --headless=true --api-version=2 exec ./apiserver
# Run specific test patterns
test-pattern:
@if [ -z "$(PATTERN)" ]; then \
echo "Usage: make test-pattern PATTERN=TestName"; \
exit 1; \
fi
@echo "🧪 Running tests matching: $(PATTERN)"
go test -v ./internal/apiserver/... -run="$(PATTERN)"
# Install development tools
install-tools:
@echo "🛠️ Installing development tools..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install github.com/swaggo/swag/cmd/swag@latest
@echo "✅ Development tools installed"
# Swagger documentation
swag-setup:
@echo "📖 Setting up Swagger documentation..."
@echo "⚠️ Installing swag tool..."
go install github.com/swaggo/swag/cmd/swag@latest
@echo "✅ swag installed"
@echo "📋 Initializing Swagger configuration..."
swag init -g cmd/apiserver/main.go -o internal/apiserver/docs
@echo "✅ Swagger documentation generated"
.PHONY: help build test test-coverage test-race fmt vet clean docker-up docker-down swag-setup