-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
115 lines (86 loc) · 2.76 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
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
#!make
# default variables
#
NAME=best-ever-golang-starter
# build
#
build-simple-blog-graphql:
@go build -o build/$(NAME)-gateway cmd/simple-blog-graphql/main.go
.PHONY: build-simple-blog-graphql
# run
#
run-simple-blog-graphql:
@go run cmd/simple-blog-graphql/main.go
.PHONY: run-simple-blog-graphql
# gqlgen
#
gqlgen:
@go run github.com/99designs/gqlgen generate --config cmd/simple-blog-graphql/gqlgen.yml
.PHONY: gqlgen
# sqlc
#
# generate sqlc queries based on the schema and sqlc.yaml file
sqlc-generate:
@go run github.com/sqlc-dev/sqlc/cmd/sqlc generate
.PHONY: sqlc-generate
# test
#
# unit test
#
unit-test-coverage:
@go test $(shell go list ./internal/module/... | grep -v '\-querier') -coverprofile cover.out
go tool cover -func cover.out
@rm cover.out
.PHONY: unit-test-coverage
# mockery
#
# generate mocks for a given interface | usage: make name=HealthService mock
# optional filename | usage: make name=HealthService filename=mock_health_service.go mock
# optional srcpkg | usage: make name=HealthService srcpkg=github.com/yoyr/pkg mock
# optional structname | usage: make name=HealthService structname=X mock
mock:
@echo "Generating mock for $(name)..."
@cmd="go run github.com/vektra/mockery/v2@latest --name=$(name) --recursive"; \
if [ -n "$(filename)" ]; then \
cmd="$$cmd --filename=$(filename)"; \
fi; \
if [ -n "$(srcpkg)" ]; then \
cmd="$$cmd --srcpkg=$(srcpkg)"; \
fi; \
if [ -n "$(structname)" ]; then \
cmd="$$cmd --structname=$(structname)"; \
fi; \
eval $$cmd
.PHONY: mock
# postgres migration
#
postgres_uri="no pstgres_uri loaded from env"
env_file=.env
version=
ifneq ("$(wildcard $(env_file))","")
include $(env_file)
endif
# Check if SSL is disabled and set the appropriate SSL mode
ifeq ($(POSTGRES_IS_SSL_DISABLED),true)
ssl_mode=?sslmode=disable
else
ssl_mode=
endif
# Construct the postgres URI
postgres_uri:=$(POSTGRES_URI)/$(POSTGRES_DATABASE)$(ssl_mode)
# jump to the next version
migrate-up:
@go run github.com/golang-migrate/migrate/v4/cmd/migrate -path db/migration -database $(postgres_uri) --verbose up $(version)
# use a specific version | usage: make version=1 migrate-goto
migrate-goto:
@migrate -path db/migration -database $(postgres_uri) --verbose goto $(version)
# force a specific version | usage: make version=1 migrate-force
migrate-force:
@migrate -path db/migration -database $(postgres_uri) --verbose force $(version)
# jump back to the previous version
migrate-down:
@migrate -path db/migration -database $(postgres_uri) --verbose down 1
# print current migration version
migrate-version:
@migrate -path db/migration -database $(postgres_uri) --verbose version
.PHONY: migrate-up migrate-goto migrate-force migrate-down migrate-version