Skip to content

Commit 0e3cc13

Browse files
committed
build: added makefile
build: added makefile
1 parent 7c29430 commit 0e3cc13

File tree

2 files changed

+92
-15
lines changed

2 files changed

+92
-15
lines changed

Makefile

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
.PHONY: build-server start-server stop-server live-reload test test-coverage clean-deps format clean-imports lint vet check-shadow lint-format migrate-create migrate-up
2+
3+
# Define variable for migration directory and PostgreSQL URL
4+
MIGRATION_DIR = /migration
5+
POSTGRESQL_URL = your_postgresql_connection_string # Replace with your actual connection string
6+
7+
# Docker tasks
8+
build-server:
9+
docker-compose -p go-vertical-slice-architecture build
10+
11+
start-server:
12+
docker-compose up -d
13+
14+
stop-server:
15+
docker-compose down
16+
17+
# Standalone usage for live reloading
18+
live-reload:
19+
air
20+
21+
# Testing
22+
test:
23+
go test ./...
24+
25+
test-coverage:
26+
go test -cover ./...
27+
28+
# Cleaning, Formatting, Linting, and Vetting
29+
clean-deps:
30+
go mod tidy
31+
32+
format:
33+
go fmt ./...
34+
35+
clean-imports:
36+
goimports -l -w .
37+
38+
lint:
39+
golangci-lint run ./...
40+
41+
vet:
42+
go vet ./...
43+
44+
check-shadow:
45+
shadow ./...
46+
47+
lint-format:
48+
go fmt ./...
49+
go vet ./...
50+
golangci-lint run ./...
51+
52+
# Database Migration
53+
migrate-create:
54+
migrate create -ext sql -dir $(MIGRATIONS_DIR) -seq $(name)
55+
56+
migrate-up:
57+
migrate -database $(POSTGRESQL_URL) -path $(MIGRATIONS_DIR) up
58+
59+
# Usage instructions:
60+
# - To build the server: make build-server
61+
# - To start the server: make start-server
62+
# - To stop the server: make stop-server
63+
# - For live reloading during development: make live-reload
64+
# - To run tests: make test
65+
# - To check test coverage: make test-coverage
66+
# - To clean dependencies: make clean-deps
67+
# - To format code: make format
68+
# - To clean unused imports: make clean-imports
69+
# - To lint code: make lint
70+
# - To vet code: make vet
71+
# - To check for shadowed variables: make check-shadow
72+
# - To lint, format and vet your once: make lint-format
73+
# - To create a migration script (replace your_script_name with the actual name): make migrate-create name=your_script_name
74+
# - To run migration scripts: make migrate-up

README.md

+18-15
Original file line numberDiff line numberDiff line change
@@ -258,64 +258,67 @@ https://github.com/sebajax/go-vertical-slice-architecture/blob/eb79ccae805d23b6f
258258

259259
```bash
260260
# Build server
261-
docker-compose -p go-vertical-slice-architecture build
261+
make build-server
262262

263263
# Start server
264-
docker-compose up -d
264+
make start-server
265265

266266
# Stop server
267-
docker-compose down
267+
make stop-server
268268
```
269269

270270
### Standalone usage
271271

272272
```bash
273273
# Live reload
274-
air
274+
make live-reload
275275
```
276276

277277
### Testing
278278

279279
```bash
280280
# To run unit testing
281-
go test
281+
make test
282282

283283
# To run unit testing coverage
284-
go test -cover ./...
284+
make test-coverage
285285
```
286286

287287
### Formatting, Linting and Vetting
288288

289289
```bash
290290
# Clean dependencies
291-
go mod tidy
291+
make clean-deps
292292

293293
# Run formating
294-
go fmt ./...
294+
make format
295295

296296
# Remove unused imports
297-
goimports -l -w .
297+
make clean-imports
298298

299299
# Run linting
300-
golangci-lint run ./...
300+
make lint
301301

302302
# Run vetting
303-
go vet ./...
303+
make vet
304304

305305
# Run shadow to check shadowed variables
306306
# Install shadow
307307
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest
308308
# Run shadow
309-
shadow ./...
309+
make check-shadow
310+
311+
# Run vetting to lint, format and vet your once
312+
make lint-format
310313
```
311314

312315
### Database migration script
313316

314317
```bash
315-
# Create the script
316-
migrate create -ext sql -dir /migrations -seq [script_name]
318+
# Create the script (replace your_script_name with the actual name)
319+
make migrate-create name=your_script_name
317320
# Run the script
318-
migrate -database ${POSTGRESQL_URL} -path /migrations up
321+
make migrate-up
319322

320323
# It will run automatically when the database initializes
321324
```

0 commit comments

Comments
 (0)