-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
172 lines (144 loc) · 5.25 KB
/
Copy pathMakefile
File metadata and controls
172 lines (144 loc) · 5.25 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
.PHONY: build test test-unit test-integration test-coverage clean run dev docker help preprocess
# Variables
BINARY_NAME=analytics-dashboard
MAIN_PATH=./cmd/server
BUILD_DIR=./bin
TEST_COVERAGE_DIR=./coverage
GO_FILES=$(shell find . -name "*.go" -type f -not -path "./vendor/*")
# Default target
all: clean test build
# Build the application
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
# Run the application
run: build
@echo "Running $(BINARY_NAME)..."
./$(BUILD_DIR)/$(BINARY_NAME)
# Development mode with hot reload (requires air: go install github.com/cosmtrek/air@latest)
dev:
@echo "Starting development server with hot reload..."
air -c .air.toml
# Run all tests
test: test-unit test-integration
# Run unit tests
test-unit:
@echo "Running unit tests..."
go test -v -race -timeout 30s ./tests/unit/...
# Run integration tests
test-integration:
@echo "Running integration tests..."
go test -v -race -timeout 60s ./tests/integration/...
# Generate test coverage report
test-coverage:
@echo "Generating test coverage report..."
@mkdir -p $(TEST_COVERAGE_DIR)
@go test -v -race -coverprofile=$(TEST_COVERAGE_DIR)/coverage.out -covermode=atomic -coverpkg=./internal/...,./pkg/... ./tests/unit/... || true
@go tool cover -html=$(TEST_COVERAGE_DIR)/coverage.out -o $(TEST_COVERAGE_DIR)/coverage.html
@echo "Coverage report generated: $(TEST_COVERAGE_DIR)/coverage.html"
# Load test (requires hey: go install github.com/rakyll/hey@latest)
load-test:
@echo "Running load test..."
hey -n 1000 -c 10 -m GET http://localhost:8080/api/v1/analytics
# Format Go code
fmt:
@echo "Formatting Go code..."
gofmt -s -w $(GO_FILES)
# Lint Go code (requires golangci-lint)
lint:
@echo "Linting Go code..."
golangci-lint run
# Vet Go code
vet:
@echo "Vetting Go code..."
go vet ./...
# Security scan (requires gosec: go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest)
security:
@echo "Running security scan..."
gosec ./...
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
rm -rf $(BUILD_DIR)
rm -rf $(TEST_COVERAGE_DIR)
go clean -cache
go clean -testcache
# Install dependencies
deps:
@echo "Installing dependencies..."
go mod download
go mod tidy
# Build Docker image
docker:
@echo "Building Docker image..."
docker build -t analytics-dashboard:latest -f Dockerfile .
# Run with Docker
docker-run:
@echo "Running with Docker..."
docker run -p 8080:8080 -v $(PWD)/data:/app/data analytics-dashboard:latest
# Database migrations (for future use)
migrate-up:
@echo "Running database migrations..."
# migrate -path ./data/migrations -database "postgres://user:pass@localhost/db?sslmode=disable" up
migrate-down:
@echo "Reverting database migrations..."
# migrate -path ./data/migrations -database "postgres://user:pass@localhost/db?sslmode=disable" down
# Generate API documentation
docs:
@echo "Generating API documentation..."
# swag init -g cmd/server/main.go -o ./docs/swagger
# Performance profiling
profile:
@echo "Starting CPU profiling..."
go test -cpuprofile=cpu.prof -memprofile=mem.prof -bench=. ./tests/benchmark/
go tool pprof cpu.prof
# Memory profiling
profile-mem:
@echo "Starting memory profiling..."
go test -memprofile=mem.prof -bench=. ./tests/benchmark/
go tool pprof mem.prof
# Check for vulnerabilities
vuln-check:
@echo "Checking for vulnerabilities..."
go list -json -m all | nancy sleuth
# Generate mocks (requires mockgen: go install github.com/golang/mock/mockgen@latest)
mocks:
@echo "Generating mocks..."
mockgen -source=internal/services/interfaces.go -destination=tests/mocks/services.go
mockgen -source=internal/repository/interfaces.go -destination=tests/mocks/repository.go
# Setup development environment
setup-dev: deps
@echo "Setting up development environment..."
@echo "Installing development tools..."
go install github.com/cosmtrek/air@latest
go install github.com/rakyll/hey@latest
go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest
go install github.com/golang/mock/mockgen@latest
@echo "Creating data directories..."
mkdir -p ./data/raw ./data/processed ./data/migrations
@echo "Development environment setup complete!"
# Help
help:
@echo "Available commands:"
@echo " build - Build the application"
@echo " run - Build and run the application"
@echo " dev - Run in development mode with hot reload"
@echo " test - Run all tests"
@echo " test-unit - Run unit tests"
@echo " test-integration - Run integration tests"
@echo " test-coverage - Generate test coverage report"
@echo " benchmark - Run benchmarks"
@echo " preprocess - Preprocess CSV data"
@echo " load-test - Run load test"
@echo " fmt - Format Go code"
@echo " lint - Lint Go code"
@echo " vet - Vet Go code"
@echo " security - Run security scan"
@echo " clean - Clean build artifacts"
@echo " deps - Install dependencies"
@echo " docker - Build Docker image"
@echo " docker-run - Run with Docker"
@echo " setup-dev - Setup development environment"
@echo " help - Show this help message"