Skip to content

Commit 10e0b67

Browse files
committed
fix: more option added in make file and ORM added
1 parent 6ba6baf commit 10e0b67

File tree

10 files changed

+268
-88
lines changed

10 files changed

+268
-88
lines changed

.github/workflows/ci-cd.yml

Lines changed: 0 additions & 60 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Testing Project
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
pull_request:
9+
branches:
10+
- main
11+
- dev
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v4
21+
with:
22+
go-version: 1.23.4
23+
24+
- name: Run tests via Makefile
25+
run: make test

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ COPY --from=builder /app/got .
2727
EXPOSE 8080
2828

2929
# Command to run the application.
30-
CMD ["./go-api-template"]
30+
CMD ["./got"]

Makefile

Lines changed: 82 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ PROJECT_NAME_API=got-api
1212
PROJECT_NAME_CLI=got-cli
1313
GITHUB_USERNAME=gauravst
1414

15-
# Variables
15+
# variables
1616
BINARY_NAME=got
1717
GO_FILES=$(shell find . -name '*.go' -not -path './vendor/*')
1818
MIGRATE_PATH=./migrations
@@ -22,89 +22,88 @@ DOCKER_IMAGE_NAME=got
2222
DOCKER_TAG=latest
2323
PORT=8080
2424

25-
# Default target
25+
# default target
2626
all: build
2727

28-
# Build the application
28+
# build the application
2929
build:
3030
@echo "Building the application..."
3131
go build -o bin/$(BINARY_NAME) cmd/$(PROJECT_NAME)/main.go
3232

33-
# Run the cli application
33+
# run the api application
3434
run-api:
3535
@echo "Running the application..."
3636
go run cmd/$(PROJECT_NAME_API)/main.go
3737

38-
# Run the cli application
38+
# run the cli application
3939
run-cli:
4040
@echo "Running the application..."
4141
go run cmd/$(PROJECT_NAME_CLI)/main.go
4242

43-
# Run tests
43+
# run tests
4444
test:
4545
@echo "Running tests..."
4646
go test -v ./...
4747

48-
# Format code
48+
# format code
4949
fmt:
5050
@echo "Formatting code..."
5151
go fmt ./...
5252

53-
# Clean build artifacts
53+
# clean build artifacts
5454
clean:
5555
@echo "Cleaning up..."
5656
rm -rf bin/
5757

58-
# Install dependencies
58+
# install dependencies
5959
deps:
6060
@echo "Installing dependencies..."
6161
go mod tidy
6262

63-
# Run all up migrations
63+
# run all up migrations
6464
migrate-up:
6565
migrate -path $(MIGRATE_PATH) -database $(DB_URL) up
6666

67-
# Run all down migrations
67+
# run all down migrations
6868
migrate-down:
6969
migrate -path $(MIGRATE_PATH) -database $(DB_URL) down
7070

71-
## Build the Docker image
71+
## build the Docker image
7272
docker-build:
7373
docker build -t $(DOCKER_IMAGE_NAME):$(DOCKER_TAG) .
7474

75-
## Run the Docker container
75+
## run the Docker container
7676
docker-run:
7777
docker run -p $(PORT):$(PORT) $(DOCKER_IMAGE_NAME):$(DOCKER_TAG)
7878

79-
## Stop the Docker container
79+
## stop the Docker container
8080
docker-stop:
8181
docker stop $$(docker ps -q --filter ancestor=$(DOCKER_IMAGE_NAME):$(DOCKER_TAG))
8282

83-
## Remove the Docker container
83+
## remove the Docker container
8484
docker-rm:
8585
docker rm $$(docker ps -a -q --filter ancestor=$(DOCKER_IMAGE_NAME):$(DOCKER_TAG))
8686

87-
## Remove the Docker image
87+
## remove the Docker image
8888
docker-rmi:
8989
docker rmi $(DOCKER_IMAGE_NAME):$(DOCKER_TAG)
9090

91-
## Clean up Docker resources (stop, remove container, and remove image)
91+
## clean up Docker resources (stop, remove container, and remove image)
9292
docker-clean: docker-stop docker-rm docker-rmi
9393

94-
# Combined commands
95-
96-
## Build and run the Go application
94+
## build and run the Go application
9795
all: build run
9896

99-
## Build and run the Docker container
97+
## build and run the Docker container
10098
docker-all: docker-build docker-run
10199

102-
# Run all checks (format, test, build)
100+
# run all checks (format, test, build)
103101
check: fmt test build
104102

105103
# template migrate
106104
SHELL := bash
107105

106+
# setup for project
108107
setup:
109108
@bash -c '\
110109
echo "Enter your GitHub username :-"; \
@@ -115,6 +114,20 @@ setup:
115114
read API_APP; \
116115
echo "Do you need CLI App? (y/n) :-"; \
117116
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; \
118131
LOWER_USERNAME=$$(echo $$USERNAME | tr "[:upper:]" "[:lower:]"); \
119132
LOWER_PROJECT=$$(echo $$PROJECT | tr "[:upper:]" "[:lower:]"); \
120133
NEW_IMPORT=github.com/$$LOWER_USERNAME/$$LOWER_PROJECT; \
@@ -139,6 +152,53 @@ setup:
139152
mv $(OLD_CMD_DIR_CLI)/main.go $$NEW_CMD_DIR-cli/main.go; \
140153
rm -rf $(OLD_CMD_DIR_CLI); \
141154
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; \
142202
echo "Replacing imports..."; \
143203
find . -type f -name "*.go" -exec sed -i "s|$(OLD_IMPORT)|$$NEW_IMPORT|g" {} +; \
144204
find . -type f -name "go.mod" -exec sed -i "s|$(OLD_IMPORT)|$$NEW_IMPORT|g" {} +; \

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# GOT - Go Template
22

3-
![Version](https://img.shields.io/badge/version-0.1.0--alpha-blue)
3+
![Version](https://img.shields.io/badge/version-0.2.0--alpha-blue)
44
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
55

66
A Production-Ready Go template to kickstart your next Go lang Project.
@@ -18,14 +18,15 @@ A Production-Ready Go template to kickstart your next Go lang Project.
1818
## Features
1919

2020
- Database Support
21+
- ORM Support
2122
- Docker Integration
2223
- Makefile Commands
2324
- CLI Support
2425
- REST API Ready
2526
- Database Migrations
2627
- Environment Config
2728
- Modular Structure
28-
- Testing Framework
29+
- Testing e2e/integration/unit Support
2930

3031
## Setup
3132

go.mod

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,26 @@ require (
1111
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
1212
github.com/ilyakaznacheev/cleanenv v1.5.0 // indirect
1313
github.com/inconshreveable/mousetrap v1.1.0 // indirect
14+
github.com/jackc/pgpassfile v1.0.0 // indirect
15+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
16+
github.com/jackc/pgx/v5 v5.7.5 // indirect
17+
github.com/jackc/puddle/v2 v2.2.2 // indirect
18+
github.com/jinzhu/inflection v1.0.0 // indirect
19+
github.com/jinzhu/now v1.1.5 // indirect
1420
github.com/joho/godotenv v1.5.1 // indirect
1521
github.com/leodido/go-urn v1.4.0 // indirect
1622
github.com/lib/pq v1.10.9 // indirect
23+
github.com/mattn/go-sqlite3 v1.14.28 // indirect
1724
github.com/spf13/cobra v1.9.1 // indirect
1825
github.com/spf13/pflag v1.0.6 // indirect
19-
golang.org/x/crypto v0.32.0 // indirect
26+
golang.org/x/crypto v0.39.0 // indirect
2027
golang.org/x/net v0.34.0 // indirect
21-
golang.org/x/sys v0.29.0 // indirect
22-
golang.org/x/text v0.21.0 // indirect
28+
golang.org/x/sync v0.15.0 // indirect
29+
golang.org/x/sys v0.33.0 // indirect
30+
golang.org/x/text v0.26.0 // indirect
2331
gopkg.in/yaml.v3 v3.0.1 // indirect
32+
gorm.io/driver/postgres v1.6.0 // indirect
33+
gorm.io/driver/sqlite v1.6.0 // indirect
34+
gorm.io/gorm v1.30.0 // indirect
2435
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 // indirect
2536
)

0 commit comments

Comments
 (0)