-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
122 lines (93 loc) · 3.61 KB
/
Copy pathMakefile
File metadata and controls
122 lines (93 loc) · 3.61 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
include .env
export $(shell sed 's/=.*//' .env)
MODULE := github.com/racibaz/go-arch
GO_OUT := .
DB_URL=postgresql://$(DB_USER):$(DB_PASS)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=disable&search_path=public
default: help
help:
@echo "Makefile commands:"
@echo " make run - Run the application"
@echo " make db_create_migration - Create a new database migration"
@echo " make db_migrate_up - Apply all up database migrations"
@echo " make db_migrate_down - Apply all down database migrations"
@echo " make db_migrate_drop - Drop all database objects"
@echo " make db_migrate_version - Show current migration version"
@echo " make db_migrate_force version=<version number> - Force set migration version"
@echo " make seed port=<port number> - Seed the database with initial data"
@echo " make mock - Generate mocks using mockery"
@echo " make mock-install - Install mockery tool"
@echo " make mock-clean - Remove all generated mocks"
@echo " make generate_proto DIR=<dir> - Generate gRPC protobuf code"
@echo " "
@echo " Example Usage For Post Module : "
@echo " "
@echo " make generate_proto DIR=internal/modules/post/presentation/grpc/proto"
@echo " "
@echo " "
@echo " make generate_swagger - Generate Swagger documentation"
@echo " make test - Run unit tests"
@echo " make coverage - Run tests with coverage report"
@echo " make lint - Run code linting"
@echo " make ci-lint - Run golangci-lint for CI"
@echo " make fmt - Format the code using golangci-lint"
@echo " make module name=<name> - Create a new module with the specified name"
@echo " "
@echo " Example Usage For Module Generator : "
@echo " "
@echo " make module name=YourModuleName"
@echo " "
@echo " "
run:
@go run main.go serve
db_create_migration:
migrate create -ext sql -dir migrations -seq $(name)
db_migrate_up:
migrate -path migrations -database "$(DB_URL)" up
db_migrate_down:
migrate -path migrations -database "$(DB_URL)" down
db_migrate_drop:
migrate -path migrations -database "$(DB_URL)" drop
db_migrate_version:
migrate -path migrations -database "$(DB_URL)" version
db_migrate_force:
migrate -path migrations -database "$(DB_URL)" force $(version)
seed:
@go run main.go seed
mock:
@echo "Generating mocks using mockery..."
@go run github.com/vektra/mockery/v3 --config .mockery.yaml
mock-install:
@echo "Installing mockery..."
@go install github.com/vektra/mockery/v3@latest
mock-clean:
@echo "Cleaning generated mocks..."
@find internal/modules/post/testing/mocks -name "*_mock.go" -delete
test:
go test -v ./...
coverage:
go test -v -cover ./...
go test -v -coverprofile=coverage.txt ./...
go tool cover -func=coverage.txt
go tool cover -html=coverage.txt -o coverage.html
lint:
go vet ./...
ci-lint:
golangci-lint run --config .golangci.yaml
fmt:
golangci-lint fmt --config .golangci.yaml
.PHONY: generate_proto
generate_proto:
@echo "Generating proto for $(DIR)"
protoc \
--proto_path=$(DIR) \
--go_out=$(GO_OUT) \
--go_opt=module=$(MODULE) \
--go-grpc_out=$(GO_OUT) \
--go-grpc_opt=module=$(MODULE) \
$$(find $(DIR) -name "*.proto")
generate_swagger:
swag init -o docs/api/openapi-spec
module:
@if [ -z "$(name)" ]; then echo "Usage: make module name=<module_name>"; exit 1; fi
@bash ./scripts/create_module.sh $(name)
@echo "Module '$(name)' created successfully."