-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
65 lines (54 loc) · 1.53 KB
/
Copy pathMakefile
File metadata and controls
65 lines (54 loc) · 1.53 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
# Variables
BINARY_NAME=api
GO_FILES=$(shell find . -name '*.go' -not -path "./vendor/*")
GOLANGCI_LINT_VERSION=latest
.PHONY: all build clean test coverage lint run docker-build docker-run help
# Default target
all: lint test build
## Build: Compile the binary
build:
@echo "Building..."
CGO_ENABLED=0 go build -ldflags="-s -w" -o $(BINARY_NAME) ./cmd/api
## Clean: Remove binary and coverage files
clean:
@echo "Cleaning..."
rm -f $(BINARY_NAME) coverage.txt
## Test: Run unit tests
test:
@echo "Running tests..."
go test -v -race ./...
## Coverage: Run tests with coverage report
coverage:
@echo "Running tests with coverage..."
go test -v -race -coverprofile=coverage.txt ./...
go tool cover -func=coverage.txt
## Lint: Run golangci-lint
lint:
@echo "Linting..."
golangci-lint run
## Run: Run the application locally
run:
@echo "Running application..."
go run ./cmd/api
## Docker Build: Build the Docker image
docker-build:
@echo "Building Docker image..."
docker build -t wherego:latest .
## Docker Run: Run the Docker container
docker-run:
@echo "Running Docker container..."
docker run -p 8080:8080 wherego:latest
## Help: Show this help message
help:
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " %-15s %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)