Gin: High-Performance HTTP Web Framework for Go
What Gin is
Gin is an HTTP web framework written in Go. The README describes it as a high-performance framework with a Martini-like API but significantly better performance, "up to 40 times faster" according to the project, thanks to httprouter. It is designed for building REST APIs, web applications and microservices where speed and developer productivity both matter.
The pitch is Express.js-style routing with Go's performance characteristics. Instead of wiring net/http handlers, a router, a JSON encoder, validation and panic recovery yourself, Gin bundles them behind a small API built around a gin.Context that carries the request, the response writer, path parameters and helpers for binding and rendering. The README lists its sweet spots as high-throughput REST APIs, microservices handling many concurrent requests, web applications that need fast responses, and quick prototypes with minimal boilerplate.
Gin has been around since 2014 and is one of the most widely used Go web frameworks. The README lists open-source projects that use it in production, including the gorush push notification server, the Fn serverless platform, PhotoPrism, the Lura API gateway framework, picfit and the dkron job scheduler. The current release line is Gin 1.12.0.
How it works
A Gin application creates an engine, registers handlers on routes, and runs an HTTP server. gin.Default() returns an engine with the Logger and Recovery middleware attached; gin.New() returns a blank engine with no middleware. Routing uses a custom version of httprouter, which the README credits for a zero-allocation router with no heap allocations per request.
Middleware is a chain of handler functions. You attach it globally with Use, per route by listing extra handlers before the endpoint, or per group: Group creates a route prefix with its own middleware, and groups can be nested. Handlers read input through binding methods and write output through rendering methods on the context.
Binding comes in two flavours. The "must bind" methods (Bind, BindJSON, BindQuery and friends) abort the request with a 400 on error. The "should bind" methods (ShouldBind, ShouldBindJSON and so on) return the error and leave handling to you. Validation is done by go-playground/validator v10 through binding struct tags such as binding:"required".
Key features
- Zero-allocation router: memory-efficient routing with path parameters, querystring parameters and route grouping.
- Middleware system: built-in Logger, Recovery and BasicAuth middleware, plus custom middleware and custom recovery behaviour.
- Crash-free by default: the Recovery middleware catches panics and returns a 500 instead of taking the server down.
- Request binding and validation: JSON, XML, YAML, TOML and form data, plus URI, header and query-only binding, default values and custom validators.
- Rendering: XML, JSON, YAML, TOML and ProtoBuf responses, with SecureJSON, JSONP, AsciiJSON and PureJSON variants, HTML templates with custom delimiters and functions, and static file serving.
- The QUERY method: Gin supports the HTTP
QUERYmethod from RFC 10008, which carries a query in the request body while staying safe and idempotent. - Swappable JSON codec: build tags replace
encoding/jsonwith jsoniter, go-json or sonic, and anomsgpacktag drops MsgPack rendering to shrink binaries. - Server configuration: custom
http.Serversettings, Let's Encrypt support, multiple services in one process, graceful shutdown and cookie helpers. - Testability: handlers are exercised with the standard
net/http/httptestpackage.
Getting started
Gin requires Go 1.26 or above. With Go modules you import the package and Go fetches it at build time. The README's first application is a complete server with one JSON endpoint:
package main
import (
"log"
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
// Create a Gin router with default middleware (logger and recovery)
r := gin.Default()
// Define a simple GET endpoint
r.GET("/ping", func(c *gin.Context) {
// Return JSON response
c.JSON(http.StatusOK, gin.H{
"message": "pong",
})
})
// Start server on port 8080 (default)
// Server will listen on 0.0.0.0:8080 (localhost:8080 on Windows)
if err := r.Run(); err != nil {
log.Fatalf("failed to run server: %v", err)
}
}
Save it as main.go, then run it and visit http://localhost:8080/ping to get {"message":"pong"}:
go run main.go
To build with an alternative JSON package, or without MsgPack rendering, the quick start guide uses build tags:
go build -tags=jsoniter .
go build -tags=nomsgpack .
Beyond the README, the repository's quick start guide in docs/doc.md covers routing, middleware, logging, binding, rendering, server configuration and testing, the gin-gonic/examples repository has ready-to-run examples, and the Go team's own tutorial "Developing a RESTful API with Go and Gin" uses it.
Use cases
- JSON REST APIs: route groups for versioned endpoints, struct binding with validation tags, and JSON rendering cover most CRUD services.
- Microservices: a small binary with a fast router and Recovery middleware suits services that handle many concurrent requests.
- Server-rendered web apps: HTML templates, static files, cookies and multipart file uploads are built in.
- API gateways and infrastructure services: projects such as Lura and gorush listed in the README show Gin used as the HTTP layer of larger systems.
- Prototypes:
gin.Default()plus a handful of routes gets a working service running with very little code.
How it compares
The README includes a routing benchmark (the GitHub API route set) against many Go routers and frameworks, including Echo, Chi, Gorilla Mux, Beego, Martini, HttpRouter and others. In that table Gin records 27,364 ns/op with 0 B/op and 0 allocations, far ahead of allocation-heavy routers such as Gorilla Mux and Martini. The same table also shows a few routers with lower ns/op on that benchmark, including Aero, HttpRouter and LARS, while Echo is close behind Gin, so "fastest" depends on what you measure. Router speed is rarely the bottleneck in a real service; the more practical differences are API style, middleware ecosystem and documentation.
Compared with using only the standard library's net/http, Gin adds binding, validation, rendering and middleware conventions in exchange for a dependency. Compared with Martini, whose API it resembles, the README claims much better performance.
Things to know before adopting
- Licence: MIT, which is permissive and simple to use in commercial code.
- Trusted proxies: the docs warn that Gin trusts all proxies by default when you do not configure them, which they call not safe. Call
SetTrustedProxieswith your proxy addresses, orSetTrustedProxies(nil)if there is no proxy, soClientIP()cannot be spoofed via forwarded headers. Behind a CDN,Engine.TrustedPlatformis the alternative. - Go version: the current README requires Go 1.26 or above, which can matter for teams pinned to older toolchains.
- Bind vs ShouldBind: the must-bind methods write a 400 and set headers on failure; trying to change the status afterwards produces a warning. Use the ShouldBind variants when you want your own error responses.
- Graceful shutdown is not automatic; the docs show using
http.Server'sShutdown()or third-party packages. - Middleware lives elsewhere: CORS, JWT, sessions, rate limiting, compression and tracing come from the gin-contrib organization rather than the core package.
router.SetTrustedProxies([]string{"192.168.1.2"})
Project activity
As of October 2026 the repository has about 89,400 stars and roughly 8,800 forks. It was created in June 2014, is written in Go and licensed under MIT, and its latest push was in October 2026. The README credits hundreds of contributors, and contribution guidelines are in CONTRIBUTING.md.
Source code is at github.com/gin-gonic/gin, documentation in several languages is on gin-gonic.com, and the API reference is on pkg.go.dev.
Enjoying this project?
Discover more amazing open-source projects on TechLogHub. We curate the best developer tools and projects.
Repository:https://github.com/gin-gonic/gin
GitHub - gin-gonic/gin: Gin: High-Performance HTTP Web Framework for Go
Gin is an MIT-licensed HTTP web framework for Go with a zero-allocation router, middleware, panic recovery, JSON binding and validation, and rendering for JSON,...
github - gin-gonic/gin
Related Projects
Caddy: Web Server With Automatic HTTPS
Go web server and reverse proxy with automatic HTTPS, a simple Caddyfile and a live JSON config API.
Gitea: Self-Hosted Git Service with CI/CD and Packages
Lightweight self-hosted Git forge with pull requests, issues, packages and Actions CI/CD.
LocalAI: Self-Hosted OpenAI-Compatible AI Engine
Self-hosted engine that runs LLM, voice, image and video models behind OpenAI-compatible APIs.
Maintain Gin: High-Performance HTTP Web Framework for Go? Add the badge to your README
Show that the project is featured on TechLogHub and send readers to this write-up.
[](https://techloghub.com/open-source/gin-web-framework?utm_source=techloghub_badge&utm_medium=referral&utm_campaign=readme)
