-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
117 lines (98 loc) · 2.9 KB
/
Makefile
File metadata and controls
117 lines (98 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
.PHONY: help tests openapi build run migrate clean docker-up docker-down
# Default target - show help
help:
@echo "Available targets:"
@echo " make tests - Run all tests"
@echo " make openapi - Generate OpenAPI/Swagger documentation"
@echo " make build - Build the API server"
@echo " make run - Run the API server"
@echo " make migrate - Run database migrations"
@echo " make docker-up - Start Docker containers"
@echo " make docker-down - Stop Docker containers"
@echo " make clean - Clean build artifacts"
# Run all tests
tests:
@echo "Running all tests..."
go test ./tests/... -v
# Run tests with coverage
tests-coverage:
@echo "Running tests with coverage..."
go test ./tests/... -v -cover -coverprofile=coverage.out
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Generate OpenAPI/Swagger documentation
openapi:
@echo "Generating OpenAPI documentation..."
$(HOME)/go/bin/swag init -g cmd/api/main.go -o docs
@echo "Documentation generated in docs/ folder"
@echo "View at: http://localhost:8080/swagger/index.html"
# Build the API server
build:
@echo "Building API server..."
go build -o bin/api cmd/api/main.go
@echo "Binary created: bin/api"
# Build the migration tool
build-migrate:
@echo "Building migration tool..."
go build -o bin/migrate cmd/migrate/main.go
@echo "Binary created: bin/migrate"
# Run the API server
run:
@echo "Starting API server..."
go run cmd/api/main.go
# Run database migrations
migrate:
@echo "Running database migrations..."
go run cmd/migrate/main.go up
# Create an API key
create-key:
@echo "Creating API key..."
go run cmd/createkey/main.go
# Start Docker containers
docker-up:
@echo "Starting Docker containers..."
docker-compose up -d
@echo "Waiting for services to be ready..."
@sleep 3
@docker-compose ps
# Stop Docker containers
docker-down:
@echo "Stopping Docker containers..."
docker-compose down
# Stop and remove volumes
docker-clean:
@echo "Stopping Docker containers and removing volumes..."
docker-compose down -v
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
rm -rf bin/
rm -f coverage.out coverage.html
@echo "Clean complete"
# Install dependencies
deps:
@echo "Installing dependencies..."
go mod download
go mod tidy
@echo "Dependencies installed"
# Install development tools
install-tools:
@echo "Installing development tools..."
go install github.com/swaggo/swag/cmd/swag@latest
@echo "Tools installed"
# Format code
fmt:
@echo "Formatting code..."
go fmt ./...
@echo "Code formatted"
# Lint code
lint:
@echo "Linting code..."
golangci-lint run ./...
# Run everything needed for development
dev-setup: docker-up deps install-tools migrate create-key
@echo "Development environment ready!"
@echo "Run 'make run' to start the API server"
# Full test suite (unit + integration)
test-all: tests
@echo "All tests passed!"