Skip to content

Commit 188f5da

Browse files
committed
😙added: dependabot, docker (dev and prod) and rest.http files
1 parent 4cb6f9f commit 188f5da

File tree

7 files changed

+183
-1
lines changed

7 files changed

+183
-1
lines changed

‎cookiecutter.json

+2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
"docker_hub_username": "coderj001",
55
"project_name": "goapis",
66
"project_short_description": "A golang api's projects",
7+
"project_long_description": "A golang api's projects...",
78
"api_version": "v1",
89
"use_github_action": "y",
910
"use_rest_http": "y",
11+
"use_docker": "y",
1012
"docker_images_name": "goapis",
1113
"go_version": "1.20",
1214
"license": ["MIT", "BSD-3", "GNU GPL v3.0", "Apache Software License 2.0"]

‎hooks/post_gen_project.sh

+44-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/env bash
22

33
set -euo pipefail
4+
red=`tput setaf 1`
5+
green=`tput setaf 2`
6+
reset=`tput sgr0`
47
IFS=$'\n\t'
58

69
#
@@ -15,10 +18,50 @@ function echo_info() {
1518
# Step 1:
1619
#
1720

21+
if [[ echo "{{cookiecutter.use_docker}}" | grep -iq "^n" ]]; then
22+
rm -rf docker/ compose/
23+
fi
24+
25+
#
26+
# Step 2:
27+
#
28+
29+
if [[ echo "{{cookiecutter.use_rest_http}}" | grep -iq "^n" ]]; then
30+
rm -rf rest.txt
31+
elif
32+
echo_info "Install rest.http extension for vscode"
33+
mv rest.txt rest.http
34+
fi
35+
36+
#
37+
# Step 3:
38+
#
39+
40+
if [[ echo "{{cookiecutter.use_github_action}}" | grep -iq "^n" ]]; then
41+
rm -rf .github/
42+
fi
43+
44+
#
45+
# Step 4:
46+
#
47+
48+
echo_info "Setup env"
49+
cp env.example
50+
cp env.example .env
51+
echo """
52+
53+
# JWT Secret
54+
JWT_SECRET=$(openssl rand -base64 32)
55+
""" >> .env
56+
57+
#
58+
# Step 5:
59+
#
60+
1861
echo_info "Initializing Git"
1962
git init
2063
git add .
21-
git commit -n -m "Initial Commit"
64+
git commit -n -m "🔧 chore: initial commit"
2265

2366
#
2467
# Done:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gomod"
4+
directory: "/"
5+
6+
# Auto assign PRs raised to this account on Github
7+
assignees:
8+
- "{{cookiecutter.github_username}}"
9+
10+
11+
# Check for updates to dependencies once a week - Saturday
12+
schedule:
13+
interval: "weekly"
14+
day: "saturday"
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# {{ cookiecutter.project_name|replace('go', '')|upper|replace('-',' ') }}
22

3+
** {{cookiecutter.project_long_description}} **
4+
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM golang:1.20.5-alpine
2+
3+
# Set Working Dir
4+
WORKDIR /app
5+
6+
# Install nessery dependencies
7+
RUN apk --no-cache add \
8+
ca-certificates \
9+
git
10+
11+
# Copy go.mod and go.sum
12+
COPY go.mod go.sum ./
13+
14+
# Download all dependencies
15+
RUN go mod download
16+
17+
# Install Air using the recommended install script
18+
RUN go install github.com/cosmtrek/air@latest
19+
20+
# Verify Air installation
21+
RUN air -v
22+
23+
# Copy the rest of your application code
24+
COPY . .
25+
26+
# Expose port 8000
27+
EXPOSE 8000
28+
29+
# Set the entrypoint to `air`. Note the full path to the air binary.
30+
ENTRYPOINT ["air", "-c", "air.toml"]
31+
32+
# Health check
33+
HEALTHCHECK --interval=30s --timeout=3s \
34+
CMD wget --quiet --tries=1 --spider http://localhost:8000/health || exit 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
############################
2+
## Build Stage ##
3+
############################
4+
FROM golang:alpine AS build-env
5+
6+
RUN apk --no-cache add \
7+
ca-certificates \
8+
git \
9+
build-base
10+
11+
WORKDIR /app
12+
13+
COPY go.mod go.sum ./
14+
RUN go mod download
15+
16+
COPY . .
17+
RUN go build -o {{cookiecutter.project_name}} ./cmd/main.go
18+
19+
############################
20+
## Final Stage ##
21+
############################
22+
FROM alpine:latest
23+
24+
WORKDIR /app
25+
26+
COPY --from=build-env /app/{{cookiecutter.project_name}} /app/
27+
28+
ENTRYPOINT ./{{cookiecutter.project_name}}
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
@baseURL = http://localhost:8000
2+
@token = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjE2ODg1NzgwMzQsImlhdCI6MTY4ODQ5MTYzNH0.03hUcVbQUOn6MX-FoWFcThvPF9PBgozJIhYWc0V9E6Q
3+
4+
### Test API
5+
GET {{baseURL}}/health
6+
Content-Type: application/json
7+
8+
### User Register
9+
POST {{baseURL}}/user/register
10+
Content-Type: application/json
11+
12+
{
13+
"name": "John Doe",
14+
"phone": "1234567890",
15+
"email": "johndoe@example.com",
16+
"password": "password123"
17+
}
18+
19+
### User Login
20+
POST {{baseURL}}/user/login
21+
Content-Type: application/json
22+
23+
{
24+
"email": "johndoe@example.com",
25+
"password": "password123"
26+
}
27+
28+
### Create Contact
29+
POST {{baseURL}}/contact
30+
Content-Type: application/json
31+
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjE2ODg4MDA0MTMsImlhdCI6MTY4ODcxNDAxM30.nJhkx4n7VeoyQQ0hax5hsuYFG0Yo6Q4OIN3_cFqIGUw
32+
33+
{
34+
"name": "neo ai",
35+
"phone_number": "1234567891"
36+
}
37+
38+
### Mark as spam
39+
POST {{baseURL}}/spam
40+
Content-Type: application/json
41+
42+
{
43+
"phone_number": "1234567890"
44+
}
45+
46+
### Search by Name
47+
GET {{baseURL}}/search?name=neo
48+
Content-Type: application/json
49+
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjE2ODg4MDA0MTMsImlhdCI6MTY4ODcxNDAxM30.nJhkx4n7VeoyQQ0hax5hsuYFG0Yo6Q4OIN3_cFqIGUw
50+
51+
### Search by Phone Number
52+
GET {{baseURL}}/search?phone_number=1234567890
53+
Content-Type: application/json
54+
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjE2ODg4MDA0MTMsImlhdCI6MTY4ODcxNDAxM30.nJhkx4n7VeoyQQ0hax5hsuYFG0Yo6Q4OIN3_cFqIGUw
55+
56+
### User Details
57+
GET {{baseURL}}/user/1
58+
Content-Type: application/json

0 commit comments

Comments
 (0)