Skip to content

Commit

Permalink
Merge pull request #12 from Lukmanern/dev/cleanup
Browse files Browse the repository at this point in the history
Dev/cleanup
  • Loading branch information
Lukmanern authored Nov 13, 2023
2 parents 78c6292 + 2e0a5f2 commit 2bf170c
Show file tree
Hide file tree
Showing 74 changed files with 2,800 additions and 1,197 deletions.
16 changes: 10 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
APP_NAME=Gost - Go Fiber Project Starter
APP_IN_PRODUCTION=false
APP_SECRET_KEY=RandomStringHere1234
APP_ACCESS_TOKEN_TTL=14320m
APP_PORT=9009
APP_TIME_ZONE=Asia/Jakarta

DB_HOST=Host
DB_HOST=db.secret.supabase.co
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=Password
DB_PASSWORD=secret
DB_DATABASE=postgres

REDIS_URI=redis://user:@127.0.0.1:6379/1
Expand All @@ -18,6 +17,11 @@ PRIVATE_KEY=./keys/private.key

SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
SMTP_EMAIL=[email protected]
SMTP_PASSWORD=passwd
CLIENT_URL=https://important.client
SMTP_EMAIL=[email protected]
SMTP_PASSWORD=secret
CLIENT_URL=https://important.client

# supabase storage
SUPABASE_BUCKET_NAME=user_upload_public
SUPABASE_URL=https://secret.supabase.co
SUPABASE_TOKEN=SECRET
51 changes: 51 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Go Build

on:
push:
branches:
- "*"
- "*/*"
pull_request:
branches:
- "*"
- "*/*"

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ["1.19.x", "1.20.x", "1.21.x"]

steps:
- uses: actions/checkout@v3
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Display Go version
run: go version

- name: Verify dependencies
run: go mod verify

- name: Create Keys Directory
run: mkdir -p keys
working-directory: ${{ github.workspace }}

- name: Generate Self-Signed TLS Certificate
run: |
openssl req -x509 -newkey rsa:4096 -keyout keys/private.key -out keys/publickey.crt -days 365 -nodes -subj "/CN=localhost"
working-directory: ${{ github.workspace }}

- name: Show Certificate
run: |
cat keys/publickey.crt
cat keys/private.key
- name: Create .env file
run: echo "${{ secrets.ENV }}" > .env

- name: Build
run: go build -o main main.go
10 changes: 7 additions & 3 deletions .github/workflows/snyk.yml → .github/workflows/security.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
name: Go Snyk
name: Go Security

on:
push:
branches:
- "*"
- "*/*"
- "*/*/*"
pull_request:
branches:
- "*"
- "*/*"
- "*/*/*"

jobs:
security:
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v2

- name: Run GoSec Security Scanner
uses: securego/gosec@master

- uses: actions/checkout@master
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/golang@master
Expand Down
31 changes: 16 additions & 15 deletions .github/workflows/builder.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Go
name: Go Test

on:
push:
Expand All @@ -11,7 +11,7 @@ on:
- "*/*"

jobs:
build:
test:
runs-on: ubuntu-latest

services:
Expand All @@ -27,7 +27,7 @@ jobs:
strategy:
matrix:
go-version: ["1.18.x", "1.19.x", "1.20.x", "1.21.x"]
go-version: ["1.20.x"]

steps:
- uses: actions/checkout@v3
Expand All @@ -39,12 +39,6 @@ jobs:
- name: Display Go version
run: go version

- name: Install golint
run: go install golang.org/x/lint/golint@latest

- name: Run golint
run: golint ./...

- name: Verify dependencies
run: go mod verify

Expand All @@ -62,11 +56,18 @@ jobs:
cat keys/publickey.crt
cat keys/private.key
- name: Copy env
run: cp .env.example .env
- name: Create .env file
run: echo "${{ secrets.ENV }}" > .env

- name: Go Get
run: |
go get ./...
- name: Test
run: go test -race -timeout 20s ./internal/...
- name: Run migration
run: |
go run database/migration/main.go
- name: Build
run: go build -o main main.go
- name: Run Test
run: |
go test -p 1 -timeout 600s ./application/...
go test -race -timeout 600s ./controller/... ./database/... ./domain/.. ./internal/... ./repository/... ./service/...
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
.env
.env.test
/log
/keys
cover.out
cover.html
/.cover
/.cover
.dockerignore
docker-compose.yml
Dockerfile
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Lukman Ernandi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
46 changes: 16 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,45 +1,31 @@
test-clear:
go clean -testcache

test:
go test -p 1 -timeout 240s -coverprofile=cover.out ./...

test-per-dir:
go test -p 1 -timeout 120s ./application/...
go test -p 1 -timeout 120s ./controller/...
go test -p 1 -timeout 120s ./database/...
go test -p 1 -timeout 120s ./domain/...
go test -p 1 -timeout 120s ./internal/...
go test -p 1 -timeout 120s ./repository/...
go test -p 1 -timeout 120s ./service/...
go test -p 1 -timeout 120s ./tests/...

# without ./application and ./tests
# go test -race -timeout 200s ./controller/... ./database/... ./internal/... ./repository/... ./service/...
test-race:
go clean -testcache
go test -race -timeout 120s ./controller/...
go test -race -timeout 120s ./database/...
go test -race -timeout 120s ./domain/...
go test -race -timeout 120s ./internal/...
go test -race -timeout 120s ./repository/...
go test -race -timeout 120s ./service/...

migrate:
go run database/migration/main.go

run:
go run .

test-report:
test-clear:
go clean -testcache

test:
go clean -testcache
go test -p 1 -timeout 330s -coverprofile=cover.out ./...
go tool cover -html cover.out -o cover.html
del cover.out

test-race:
go clean -testcache
go test -race -timeout 200s ./controller/... ./database/... ./internal/... ./repository/... ./service/...

migrate-test-report:
go run database/migration/main.go
timeout 5
go test -p 1 -timeout 240s -coverprofile=cover.out ./...
go clean -testcache
go test -race -timeout 200s ./controller/... ./database/... ./internal/... ./repository/... ./service/...
go test -p 1 -timeout 330s -coverprofile=cover.out ./...
go tool cover -html cover.out -o cover.html
del cover.out

# !!windows only!! run redis in background
# windowsOS only
st-redis:
redis-server.exe --service-start
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
## Gost Project
<h1 align="center">Gost: Go Starter</h1>

Go-Fiber project starter, with jwt-auth and highly effective RBAC implementation.
<br>

Golang project starter with Fiber Framework, jwt-auth and highly effective bit-manipulation RBAC implementation to build a robust RestAPI Application.

&#xa0;

## :rocket: Technologies And :wrench: Tools

Techs and tools were used in this project:

- [Go](https://go.dev)
- [Fiber Framework](https://docs.gofiber.io/) → Framework for routing & HTTP handler.
- [GORM](https://gorm.io/) → Database logics & queries.
- [Supabase Services: PostgreSQL & Bucket](https://www.supabase.com) → Free database & storage (bucket).
- [Github CLI](https://cli.github.com/) → Github management for repository's secrets & etc.
- [Github Action](https://github.com/features/actions) → Automated testing and building across multiple versions of Go.
- [Snyk](https://app.snyk.io/) → Dependency scanning.
- [SonarLint, VSCode ext.](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarlint-vscode) → Detects & highlights issues that can lead to bugs & vulnerabilities.
- [GoLint](https://github.com/golang/lint) → CLI static code analytic for code-styling & many more.

&#xa0;

## :closed_book: Read List

- [Database Connection Configuration](https://www.alexedwards.net/blog/configuring-sqldb)
- [Go-Fiber Testing](https://dev.to/koddr/go-fiber-by-examples-testing-the-application-1ldf)
- [Production Checklist 1](https://aleksei-kornev.medium.com/production-readiness-checklist-for-backend-applications-8d2b0c57ccec/)
- [Production Checklist 2](https://github.com/gorrion-io/production-readiness-checklist/)
- [Production Checklist 3](https://www.cockroachlabs.com/docs/cockroachcloud/production-checklist/)
- [Deployment Checklist](https://last9.io/blog/deployment-readiness-checklists/)
- [CI with Github Actions](https://www.alexedwards.net/blog/ci-with-go-and-github-actions)
- [RestAPI Security Checklist](https://roadmap.sh/best-practices/api-security/)

&#xa0;

## :memo: License

This project is under license from MIT. For more details, see the [LICENSE](LICENSE) file.

&#xa0;
Loading

0 comments on commit 2bf170c

Please sign in to comment.