@@ -12,7 +12,7 @@ PROJECT_NAME_API=got-api
12
12
PROJECT_NAME_CLI =got-cli
13
13
GITHUB_USERNAME =gauravst
14
14
15
- # Variables
15
+ # variables
16
16
BINARY_NAME =got
17
17
GO_FILES =$(shell find . -name '* .go' -not -path './vendor/* ')
18
18
MIGRATE_PATH =./migrations
@@ -22,89 +22,88 @@ DOCKER_IMAGE_NAME=got
22
22
DOCKER_TAG =latest
23
23
PORT =8080
24
24
25
- # Default target
25
+ # default target
26
26
all : build
27
27
28
- # Build the application
28
+ # build the application
29
29
build :
30
30
@echo " Building the application..."
31
31
go build -o bin/$(BINARY_NAME ) cmd/$(PROJECT_NAME ) /main.go
32
32
33
- # Run the cli application
33
+ # run the api application
34
34
run-api :
35
35
@echo " Running the application..."
36
36
go run cmd/$(PROJECT_NAME_API ) /main.go
37
37
38
- # Run the cli application
38
+ # run the cli application
39
39
run-cli :
40
40
@echo " Running the application..."
41
41
go run cmd/$(PROJECT_NAME_CLI ) /main.go
42
42
43
- # Run tests
43
+ # run tests
44
44
test :
45
45
@echo " Running tests..."
46
46
go test -v ./...
47
47
48
- # Format code
48
+ # format code
49
49
fmt :
50
50
@echo " Formatting code..."
51
51
go fmt ./...
52
52
53
- # Clean build artifacts
53
+ # clean build artifacts
54
54
clean :
55
55
@echo " Cleaning up..."
56
56
rm -rf bin/
57
57
58
- # Install dependencies
58
+ # install dependencies
59
59
deps :
60
60
@echo " Installing dependencies..."
61
61
go mod tidy
62
62
63
- # Run all up migrations
63
+ # run all up migrations
64
64
migrate-up :
65
65
migrate -path $(MIGRATE_PATH ) -database $(DB_URL ) up
66
66
67
- # Run all down migrations
67
+ # run all down migrations
68
68
migrate-down :
69
69
migrate -path $(MIGRATE_PATH ) -database $(DB_URL ) down
70
70
71
- # # Build the Docker image
71
+ # # build the Docker image
72
72
docker-build :
73
73
docker build -t $(DOCKER_IMAGE_NAME ) :$(DOCKER_TAG ) .
74
74
75
- # # Run the Docker container
75
+ # # run the Docker container
76
76
docker-run :
77
77
docker run -p $(PORT ) :$(PORT ) $(DOCKER_IMAGE_NAME ) :$(DOCKER_TAG )
78
78
79
- # # Stop the Docker container
79
+ # # stop the Docker container
80
80
docker-stop :
81
81
docker stop $$(docker ps -q --filter ancestor=$(DOCKER_IMAGE_NAME ) :$(DOCKER_TAG ) )
82
82
83
- # # Remove the Docker container
83
+ # # remove the Docker container
84
84
docker-rm :
85
85
docker rm $$(docker ps -a -q --filter ancestor=$(DOCKER_IMAGE_NAME ) :$(DOCKER_TAG ) )
86
86
87
- # # Remove the Docker image
87
+ # # remove the Docker image
88
88
docker-rmi :
89
89
docker rmi $(DOCKER_IMAGE_NAME ) :$(DOCKER_TAG )
90
90
91
- # # Clean up Docker resources (stop, remove container, and remove image)
91
+ # # clean up Docker resources (stop, remove container, and remove image)
92
92
docker-clean : docker-stop docker-rm docker-rmi
93
93
94
- # Combined commands
95
-
96
- # # Build and run the Go application
94
+ # # build and run the Go application
97
95
all : build run
98
96
99
- # # Build and run the Docker container
97
+ # # build and run the Docker container
100
98
docker-all : docker-build docker-run
101
99
102
- # Run all checks (format, test, build)
100
+ # run all checks (format, test, build)
103
101
check : fmt test build
104
102
105
103
# template migrate
106
104
SHELL := bash
107
105
106
+ # setup for project
108
107
setup :
109
108
@bash -c ' \
110
109
echo " Enter your GitHub username :-" ; \
@@ -115,6 +114,20 @@ setup:
115
114
read API_APP; \
116
115
echo " Do you need CLI App? (y/n) :-" ; \
117
116
read CLI_APP; \
117
+ echo " Do you need Database? (y/n) :-" ; \
118
+ read DB; \
119
+ if [ " $$ DB" = " y" ]; then \
120
+ echo " postgres or sqlite? (p/s) :-" ; \
121
+ read DB_TYPE; \
122
+ echo " Do you need ORM (Gorm)? (y/n) :-" ; \
123
+ read ORM; \
124
+ fi ; \
125
+ echo " Do you need unit/e2e/integration Testing? (y/n) :-" ; \
126
+ read TESTING; \
127
+ echo " Do You need github workflow, CI/CD (y/n) :-" ; \
128
+ read WORKFLOW; \
129
+ echo " Do you need Docker file setup? (y/n) :-" ; \
130
+ read IS_DOCKER; \
118
131
LOWER_USERNAME=$$(echo $$USERNAME | tr "[:upper:]" "[:lower:]" ) ; \
119
132
LOWER_PROJECT=$$(echo $$PROJECT | tr "[:upper:]" "[:lower:]" ) ; \
120
133
NEW_IMPORT=github.com/$$ LOWER_USERNAME/$$ LOWER_PROJECT; \
@@ -139,6 +152,53 @@ setup:
139
152
mv $(OLD_CMD_DIR_CLI ) /main.go $$ NEW_CMD_DIR-cli/main.go; \
140
153
rm -rf $(OLD_CMD_DIR_CLI ) ; \
141
154
fi ; \
155
+ if [ " $$ DB" = " n" ]; then \
156
+ echo " Removing database..." ; \
157
+ rm -rf internal/database; \
158
+ else \
159
+ if [ " $$ ORM" = " y" ]; then \
160
+ echo " Adding ORM..." ; \
161
+ rm -rf migrations; \
162
+ rm -f internal/database/database.go; \
163
+ else \
164
+ echo " Adding Raw SQL setup"
165
+ rm -f internal/database/init.go; \
166
+ rm -f internal/database/postgres.go; \
167
+ rm -f internal/database/sqlite.go; \
168
+ fi ; \
169
+ if [ " $$ DB_TYPE" = " p" ]; then \
170
+ if [ " $$ ORM" = " y" ]; then \
171
+ echo " Adding Postgres Db..." ; \
172
+ rm -f internal/database/database.go; \
173
+ else \
174
+ # something here
175
+ fi ; \
176
+ else \
177
+ if [ " $$ ORM" = " y" ]; then \
178
+ echo " Adding Sqlite"
179
+ else \
180
+ # something here
181
+ fi ; \
182
+ fi ; \
183
+ fi ; \
184
+ if [ " $$ TESTING" = " n" ]; then \
185
+ echo " Removing Testing..." ; \
186
+ rm -rf test ; \
187
+ find . -type f -name ' *_test.go' -delete; \
188
+ fi ; \
189
+ if [ " $$ WORKFLOW" = " n" ]; then \
190
+ echo " Removing workflow..." ; \
191
+ rm -rf .github/workflows; \
192
+ else \
193
+ if [ " $$ TESTING" = " n" ]; then \
194
+ rm -f .github/workflows/test.yml; \
195
+ fi ; \
196
+ fi ; \
197
+ if [ " $$ IS_DOCKER" = " n" ]; then \
198
+ echo " Removing Docker setup..." ; \
199
+ rm -f Dockerfile; \
200
+ rm -f .dockerignore; \
201
+ fi ; \
142
202
echo " Replacing imports..." ; \
143
203
find . -type f -name " *.go" -exec sed -i " s|$( OLD_IMPORT) |$$ NEW_IMPORT|g" {} +; \
144
204
find . -type f -name " go.mod" -exec sed -i " s|$( OLD_IMPORT) |$$ NEW_IMPORT|g" {} +; \
0 commit comments