Releases: Massad/gin-boilerplate
v3: Modernize boilerplate with sqlx, middleware, reusable validation, and invoice PDF
What's new in v3
- sqlx migration: Replaced go-gorp with sqlx for a thinner database layer. All raw SQL queries unchanged.
- Middleware extraction: Moved CORS, RequestID, and JWT auth middleware from main.go into
middleware/package. Auth middleware calls models directly to avoid import cycles. - Reusable form validation: Replaced duplicated per-field error methods with a single
forms.Translate(err, messages)function and declarative message maps. - Invoice example: Added
invoice/package with HTML preview and PDF download using maroto (pure Go, no external binaries). - Dependency upgrades: gin 1.11, crypto 0.49, validator 10.28, gzip 1.2.5, swag 1.16.6. Removed go-gorp.
- README refreshed for v3 with API endpoint table, project structure, and new sections for invoice demo, trusted proxies, and CORS.
Security fixes
- Authorization bypass fixed: Article Update/Delete now enforce
user_idin SQL queries (previously any authenticated user could modify any article by ID). - DB SSL: PostgreSQL connection respects
SSLenv var (sslmode=requirewhenSSL=TRUE). - Logout route: Now uses
TokenAuthmiddleware for consistent 401 responses. - Login error handling:
CreateAuthfailure now returns error instead of silently issuing unusable tokens. - Token validation:
ExtractTokenMetadatareturns explicit errors instead ofnil, nilon invalid claims. - Test credential leak: Removed
fmt.Println(DB_PASS)from test output. - Trusted proxies: Added
SetTrustedProxies(nil)to prevent proxy header trust warning.
Other improvements
- Added
DB_HOSTandDB_PORTenv vars for flexible DB connection - Removed dead
TokenValidmethod from models and controllers - Replaced deprecated
ioutil.ReadAllwithio.ReadAllin tests - Fixed
UserLoginResponse.TokenSwagger type (wasstring, nowTokenstruct) - Added invoice integration tests
- Regenerated Swagger docs
v2.0
Changes:
-
Removed session-cookies auth (It can be found here if needed v1-session-cookies-auth)
-
JWT instead of session-cookies
- Token validation middleware
- Token generation
- Authorization and refresh token
-
Redis as a database not as a session storage
-
Go Modules
-
Environment (.env)
-
Updated unit test
-
Code and structure enhancements
-
Middleware:
TokenAuthMiddlewareRequestIDMiddlewaregzip.Gzip Middleware
-
Golang in travis:
1.10.x- 1.13.x
- 1.14.x
- master
- SSL Support
- Generating the certifications in
./certfolder from:
- Generating the certifications in
$ sh generate-certificate.sh
- SSL=TRUE | FALSE in .env
- SSL implementation in the server in **main.go**
- Postman:
- https://www.postman.com/collections/7f941b400a88ddd9c137
- Renamed APIs
- Added Auth -> Refresh Token API (using the
refresh_token)
Capture both access_token & refresh_token and put it in the global variable from the Login API in Tests tab
requests.
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
var jsonData = JSON.parse(responseBody);
pm.globals.set("token", jsonData.token.access_token);
pm.globals.set("refresh_token", jsonData.token.refresh_token);
});
To be used in:
Authorization -> Bearer Token
Value: {{token}} (Comes from global variables)
- PostgreSQL:
- 2 trigger functions:
public.created_at_column()public.update_at_column()
- 2 trigger functions:
Those are added to updated_at and created_at columns to update the latest timestamp automatically in both user and article tables. You can explore the tables and public schema for more info.
v1.05 (Last of v1)
HTTP Status update closing #7
This release will be the last to include the "session & cookies" authentication stored in Redis. Next versions & releases will be having the JWT as authentication.
If you still want the old school auth, you can either refer to this release or this v1-session-cookies-auth branch
v0.04
v0.03
v0.02
v0.01: Merge pull request #2 from krolow/patch-1
Fix link to gorp project