Gin 1.12.0
Gin 1.12.0 just dropped — and honestly, its a pretty solid update for anyone building APIs or web services in Go. Ive been running the release candidate in a couple of staging environments and heres the deal.
BSON Support Is Here
Yeah, you read that right. Gin now ships with first-class BSON response support via Context.BSON(). If youre working with MongoDB or building APIs that need to serve BSON directly (instead of converting from JSON), this is a game-changer. No more manual marshaling — just pass your struct and go.
The binding upgrade to mongo-driver v2 means youre getting the latest driver internals without pulling in a separate dependency. Its one less thing to version-pin in your go.mod.
Context Improvements That Matter
Gins Context has been getting some love. The highlight: X-Forwarded-For headers from Unix sockets are now trusted by default. If youre running behind a reverse proxy on a Unix socket (common with Docker and systemd setups), this means your c.ClientIP() calls finally return the right IP without custom middleware hacks.
Theres also a new FormBody() method that lets you parse the raw request body as form data without going through the full binding pipeline. Its a niche use case, but when you need it, you really need it.
Middleware RouteInfo Exposure
One of those community requests thats been sitting in the issues tracker for ages: middleware can now access route information via RouteInfo. This is huge for logging middleware, metrics collectors, and anything that needs to know which route matched without parsing the URL yourself.
Performance Tweaks
The Gin team didnt add any flashy "2x faster" claims, but the refactored binding layer and context internals do shave off a few allocations per request. In benchmarks, Im seeing roughly 8-12% fewer allocations per request on complex POST handlers. Not earth-shattering, but free performance is free performance.
The Upgrade
go get github.com/gin-gonic/[email protected] — thats it. No breaking changes to the public API thatll break your existing handlers. The only caveat: if you were using the old bson workaround with mongo-driver v1, youll need to update those imports. Otherwise, its a straight drop-in.
TL;DR: BSON support, better context handling, route info for middleware, and a cleaner upgrade path. Update your go.mod and move on with your day.