-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
74 lines (60 loc) · 1.8 KB
/
Makefile
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
# Go parameters
GOCMD = go
GOBUILD = $(GOCMD) build
GOCLEAN = $(GOCMD) clean
GOTEST = $(GOCMD) test
GOGET = $(GOCMD) get
# Init environment
init:
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
go install github.com/air-verse/air@latest
go install github.com/swaggo/swag/cmd/swag@latest
go install go.uber.org/nilaway/cmd/nilaway@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
cp ./pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
generate_sql:
sqlc generate
generate_openapi:
swag init -g main.go
# Dev target
server-dev:
go run . server
# Run example consumer: make consumer name=example
.PHONY: consumer
consumer:
go run . consumer $(name)
# Build target
build:
$(GOBUILD) -o ./bin/bunny .
migrate-up:
migrate -database postgresql://bunny:bunny@localhost:5432/bunny?sslmode=disable -path db/migrations up
migrate-down:
migrate -database postgresql://bunny:bunny@localhost:5432/bunny?sslmode=disable -path db/migrations down 1
migrate-create:
migrate create -ext sql -dir db/migrations -tz utc $(name)
# Clean target
clean:
$(GOCLEAN)
rm -rf ./generated
rm -rf ./bin
lint:
golangci-lint run .
lint-fix:
golangci-lint run --fix .
lint-changes:
@changed_files=$$(git status --porcelain | grep -E '^(M|A|R|C)' | awk '{print $$2}' | grep '\.go$$'); \
if [ -n "$$changed_files" ]; then \
echo "Running golangci-lint on changed files..."; \
golangci-lint run $$changed_files; \
else \
echo "No Go files changed. Skipping lint."; \
fi
lint-fix-changes:
@changed_files=$$(git status --porcelain | grep -E '^(M|A|R|C)' | awk '{print $$2}' | grep '\.go$$'); \
if [ -n "$$changed_files" ]; then \
echo "Running golangci-lint --fix on changed files..."; \
golangci-lint run --fix $$changed_files; \
else \
echo "No Go files changed. Skipping lint."; \
fi