Golang project starter with Fiber Framework, jwt-auth, email service and soft delete schema to build a robust RestAPI Backend Application.
Techs and tools were used in this project:
- Fiber Framework → Framework for routing & HTTP handler.
- GORM → Database logics & queries.
- PostgreSQL @ Supabase → Free database.
- Github CLI → Github repository's management.
- Github Action → Automated testing and building across multiple versions of Go.
- Snyk → Dependency scanning.
- SonarLint as VSCode ext. → Detects & highlights issues that can lead to bugs & vulnerabilities.
- GoLint → CLI static code analytic for code-styling & many more.
🏁 Run Project or see quick-setup
- Clone project
git clone https://github.com/Lukmanern/gost your_project && cd your_project
-
Delete the .git directory to prevent repository cloning. The .git directory is not visible, you can try with
rm -rf .git
command. -
Rename or copy the file .env.example to .env
-
For a quick setup, I suggest using Supabase for the database and Gmail for the system email. Then, fill all the values in the .env file.
-
Create
keys
directory, then generate keys.
mkdir keys
# unix
openssl req -x509 -newkey rsa:2048 -keyout keys/private.key -out keys/publickey.crt -days 365 -nodes -subj "/CN=localhost"
# windows: using openssl.exe
"C:\Program Files\Git\usr\bin\openssl.exe" req -x509 -newkey rsa:2048 -keyout keys/private.key -out keys/publickey.crt -days 365 -nodes -subj "/CN=localhost"
- Download all dependencies, turn on Redis, and then test the connections to the databases (DB and Redis).
go get -v ./... && go test ./database/...
- Run the project and try to hit hello endpoints : /hello and /hello/your-name
go run .
- Command list :
# db-tables drop and re-create
go run ./database/migration/.
# db connections test
go test ./database/...
# Generate keys
# unix
openssl req -x509 -newkey rsa:2048 -keyout keys/private.key -out keys/publickey.crt -days 365 -nodes -subj "/CN=localhost"
# windows: using openssl.exe
"C:\Program Files\Git\usr\bin\openssl.exe" req -x509 -newkey rsa:2048 -keyout keys/private.key -out keys/publickey.crt -days 365 -nodes -subj "/CN=localhost"
# Test
go test -race -cover ./...
# Download all package
go mod download
go get -d -v ./...
go install -v ./...
-
Create a repository on GitHub, but don't push initially. Ensure to add the Repository Secrets for GitHub Actions (SNYK_TOKEN and ENV).
-
Log in to Snyk, get the account token, and then add the token in the GitHub Repository Secret (named: SNYK_TOKEN) of the repository you created.
-
Also, add all .env values to the GitHub Repository Secret (named: ENV) for the repository. If you need a different database for GitHub Actions testing, you can modify the values.
-
Before committing and pushing, take a few minutes to review the GitHub Actions workflow at:
./.github/workflows/*.yml
-
Search/find and replace github.com/Lukmanern/gost with your project name.
-
Commit and push!
- You can use Github-CLI to set, remove, or update your GitHub Repository Secret.
> gh secret list
NAME UPDATED
ENV about 1 month ago
SNYK_TOKEN about 3 months ago
- You can receive advice from SonarLint and Golint. You don't always need to activate SonarLint; just enable it after ensuring your code runs normally. Then, commit the changes and do some code-finishing using SonarLint.
> golint ./...
domain\entity\role.go:6:6: exported type Role should have comment or be unexported
domain\entity\role.go:13:1: exported method Role.TableName should have comment or be unexported
domain\entity\user.go:10:6: exported type User should have comment or be unexported
domain\entity\user.go:20:1: exported method User.TableName should have comment or be unexported
...
- Go to Web Snyk Dashboard, then you can add all your projects from Github and other platforms. Snyk will scan your project for potential security vulnerabilities and dependencies issues. It analyzes the codebase and dependencies, providing insights into known vulnerabilities, outdated packages, and best practices for secure coding.
- Database Connection Configuration
- Go-Fiber Testing
- Production Checklist 1
- Production Checklist 2
- Production Checklist 3
- Deployment Checklist
- CI with Github Actions
- RestAPI Security Checklist
This project is under license from MIT. For more details, see the LICENSE file.