
The fastest way to deploy a RESTful API with Gin Framework — structured with PostgreSQL, JWT authentication stored in Redis, and ready to build on.
Clone the repository:
git clone https://github.com/Massad/gin-boilerplate.git
cd gin-boilerplate
Install dependencies:
go mod download
Set up your environment:
cp .env_rename_me .env
# Edit .env with your database credentials
Import the database schema:
psql -U postgres -h localhost < ./db/database.sql
The database includes trigger functions (created_at_column() and update_at_column()) that automatically manage created_at and updated_at timestamps on the user and article tables.
make run
Or directly:
go run *.go
go build -v
./gin-boilerplate
Tests are integration tests that require running PostgreSQL and Redis:
go test -v -tags=all ./tests/*
To enable SSL, set SSL=TRUE in .env and generate certificates:
mkdir cert/
sh generate-certificate.sh
To disable SSL, set SSL=FALSE in .env.
| Method | Path | Auth | Description |
|---|---|---|---|
| POST | /v1/user/register |
No | Register a new user |
| POST | /v1/user/login |
No | Login and receive JWT tokens |
| GET | /v1/user/logout |
Bearer | Logout (invalidates token) |
| Method | Path | Auth | Description |
|---|---|---|---|
| POST | /v1/article |
Bearer | Create an article |
| GET | /v1/articles |
Bearer | Get all user articles |
| GET | /v1/article/:id |
Bearer | Get one article |
| PUT | /v1/article/:id |
Bearer | Update an article |
| DELETE | /v1/article/:id |
Bearer | Delete an article |
| Method | Path | Auth | Description |
|---|---|---|---|
| POST | /v1/token/refresh |
No | Refresh access and refresh tokens |
| Method | Path | Auth | Description |
|---|---|---|---|
| GET | /v1/invoice |
No | HTML preview of a sample invoice with download button |
| GET | /v1/invoice/download |
No | Download sample invoice as PDF |
Generate and view API documentation:
make generate_docs
make run
Then open: https://localhost:9000/swagger/index.html
Once the server is running, open the invoice preview in your browser:
http://localhost:9000/v1/invoice
The page shows an HTML invoice with a Download PDF button that generates a PDF using maroto (pure Go, no external dependencies).
By default, SetTrustedProxies(nil) is configured — Gin will not trust any proxy headers. If you deploy behind a reverse proxy (nginx, CloudFlare, etc.), set your trusted proxy IPs:
r.SetTrustedProxies([]string{"192.168.1.0/24", "10.0.0.0/8"})
CORS is configured in middleware/cors.go. Update the Access-Control-Allow-Origin header for your domain in production.
This boilerplate uses Bearer Token authentication:
access_token (15 min) and refresh_token (7 days)Authorization: Bearer <access_token>/v1/token/refresh with the refresh token to get new tokenscontrollers/ HTTP handlers
models/ Database structs and queries (sqlx + raw SQL)
forms/ Request validation structs and reusable error translation
middleware/ CORS, RequestID, and JWT auth middleware
invoice/ Invoice HTML/PDF generation example
db/ PostgreSQL and Redis initialization
docs/ Swagger documentation (auto-generated)
public/ Static files and HTML templates
models/ with your SQL queriesforms/ with binding tags and a ValidationMessages mapcontrollers/ — use forms.Translate(err, messages) for validation errorsmain.gomake generate_docs to update SwaggerMIT
$ claude mcp add gin-boilerplate \
-- python -m otcore.mcp_server <graph>