gin
Gin is a high-performance HTTP web framework for Go built on a zero-allocation, httprouter-derived radix-tree router. It offers Express-style routing, middleware chains, JSON binding/validation, and built-in rendering for building REST APIs and microservices.
MITPermissive — free to use in commercial and proprietary software, with attribution.View license →
Production readiness
4/5- Actively maintainedCommits in the last 6 months
- No known vulnerabilitiesNot yet scanned
- Clear, usable licenseMIT (permissive)
- Proven adoptionWidely used
- Has documentationDocumentation indexed
go get ginOur analysis
Gin is a minimalist Go web framework centered on a fast radix-tree router with a middleware pipeline, request binding/validation, and response rendering helpers. It aims to give Express.js-like ergonomics with Go's performance.
When to use gin
Reach for Gin when building JSON REST APIs or microservices in Go where low latency and high concurrency matter, and you want a thin, well-documented layer over net/http with a large middleware ecosystem (CORS, JWT, sessions, logging) rather than a full batteries-included MVC framework.
When not to
If you want to stay on the standard library with zero dependencies, Go 1.22+ net/http routing or Chi may suffice. For raw throughput on a custom fasthttp engine, Fiber can edge it out, and for a full-stack ORM/admin/scaffolding experience Beego or a non-Go framework is a better fit. Server-rendered, template-heavy apps gain less from Gin's API-first design.
Strengths
- Zero-allocation router delivers excellent routing performance and predictable memory use
- Very large, mature ecosystem of official gin-contrib middleware
- Simple, approachable API with strong multilingual documentation
- Built-in request binding and validation, plus recovery middleware for crash resilience
- Battle-tested in many production systems and one of the most popular Go frameworks
Trade-offs
- Built on net/http, so it trails fasthttp-based frameworks like Fiber in some benchmarks
- Reflection-based binding/validation can be a source of subtle bugs and overhead
- Largely a routing + middleware layer — no ORM, auth, or project scaffolding out of the box
- Custom Context type and middleware patterns add a learning curve and some lock-in versus plain net/http
- Aggressive Go version requirements (e.g. Go 1.25+) can constrain older toolchains
Maturity
Extremely mature and actively maintained, with ~88k stars, hundreds of contributors, frequent releases (1.12.0), and widespread production adoption. It is effectively a de facto standard among Go web frameworks.
Gin Web Framework
📰 Gin 1.12.0 is now available!
We're excited to announce the release of Gin 1.12.0! This release brings new features, performance improvements, and important bug fixes. Check out the release announcement on our official blog for the full details.
Gin is a high-performance HTTP web framework written in Go. It provides a Martini-like API but with significantly better performance—up to 40 times faster—thanks to httprouter. Gin is designed for building REST APIs, web applications, and microservices where speed and developer productivity are essential.
Why choose Gin?
Gin combines the simplicity of Express.js-style routing with Go's performance characteristics, making it ideal for:
Building high-throughput REST APIs
Developing microservices that need to handle many concurrent requests
Creating web applications that require fast response times
Prototyping web services quickly with minimal boilerplate
Gin's key features:
Zero allocation router - Extremely memory-efficient routing with no heap allocations
High performance - Benchmarks show superior speed compared to other Go web frameworks
Middleware support - Extensible middleware system for authentication, logging, CORS, etc.
Crash-free - Built-in recovery middleware prevents panics from crashing your server
JSON validation - Automatic request/response JSON binding and validation
Route grouping - Organize related routes and apply common middleware
Error management - Centralized error handling and logging
Built-in rendering - Support for JSON, XML, HTML templates, and more
Extensible - Large ecosystem of community middleware and plugins
Getting Started
Prerequisites
Basic Go knowledge: Familiarity with Go syntax and package management is helpful
Installation
With Go's module support, simply import Gin in your code and Go will automatically fetch it during build:
import "github.com/gin-gonic/gin"
Your First Gin Application
Here's a complete example that demonstrates Gin's simplicity:
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)
}
}
Running the application:
Save the code above as
main.goRun the application:
go run main.goOpen your browser and visit
http://localhost:8080/pingYou should see:
{"message":"pong"}
What this example demonstrates:
Creating a Gin router with default middleware
Defining HTTP endpoints with simple handler functions
Returning JSON responses
Starting an HTTP server
Next Steps
After running your first Gin application, explore these resources to learn more:
📚 Learning Resources
Gin Quick Start Guide - Comprehensive tutorial with API examples and build configurations
Example Repository - Ready-to-run examples demonstrating various Gin use cases:
REST API development
Authentication & middleware
File uploads and downloads
WebSocket connections
Template rendering
📖 Documentation
API Reference
Go.dev API Documentation - Complete API reference with examples
User Guides
The comprehensive documentation is available on gin-gonic.com in multiple languages:
Official Tutorials
⚡ Performance Benchmarks
Gin demonstrates exceptional performance compared to other Go web frameworks. It uses a custom version of HttpRouter for maximum efficiency. View detailed benchmarks →
Gin vs. Other Go Frameworks (GitHub API routing benchmark):
Benchmark name(1)(2)(3)(4)BenchmarkGin_GithubAll4355027364 ns/op0 B/op0 allocs/opBenchmarkAce_GithubAll4054329670 ns/op0 B/op0 allocs/opBenchmarkAero_GithubAll5763220648 ns/op0 B/op0 allocs/opBenchmarkBear_GithubAll9234216179 ns/op86448 B/op943 allocs/opBenchmarkBeego_GithubAll7407243496 ns/op71456 B/op609 allocs/opBenchmarkBone_GithubAll4202922835 ns/op720160 B/op8620 allocs/opBenchmarkChi_GithubAll7620238331 ns/op87696 B/op609 allocs/opBenchmarkDenco_GithubAll1835564494 ns/op20224 B/op167 allocs/opBenchmarkEcho_GithubAll3125138479 ns/op0 B/op0 allocs/opBenchmarkGocraftWeb_GithubAll4117300062 ns/op131656 B/op1686 allocs/opBenchmarkGoji_GithubAll3274416158 ns/op56112 B/op334 allocs/opBenchmarkGojiv2_GithubAll1402870518 ns/op352720 B/op4321 allocs/opBenchmarkGoJsonRest_GithubAll2976401507 ns/op134371 B/op2737 allocs/opBenchmarkGoRestful_GithubAll4102913158 ns/op910144 B/op2938 allocs/opBenchmarkGorillaMux_GithubAll3463384987 ns/op251650 B/op1994 allocs/opBenchmarkGowwwRouter_GithubAll10000143025 ns/op72144 B/op501 allocs/opBenchmarkHttpRouter_GithubAll5593821360 ns/op0 B/op0 allocs/opBenchmarkHttpTreeMux_GithubAll10000153944 ns/op65856 B/op671 allocs/opBenchmarkKocha_GithubAll10000106315 ns/op23304 B/op843 allocs/opBenchmarkLARS_GithubAll4777925084 ns/op0 B/op0 allocs/opBenchmarkMacaron_GithubAll3266371907 ns/op149409 B/op1624 allocs/opBenchmarkMartini_GithubAll3313444706 ns/op226551 B/op2325 allocs/opBenchmarkPat_GithubAll2734381818 ns/op1483152 B/op26963 allocs/opBenchmarkPossum_GithubAll10000164367 ns/op84448 B/op609 allocs/opBenchmarkR2router_GithubAll10000160220 ns/op77328 B/op979 allocs/opBenchmarkRivet_GithubAll1462582453 ns/op16272 B/op167 allocs/opBenchmarkTango_GithubAll6255279611 ns/op63826 B/op1618 allocs/opBenchmarkTigerTonic_GithubAll2008687874 ns/op193856 B/op4474 allocs/opBenchmarkTraffic_GithubAll3553478508 ns/op820744 B/op14114 allocs/opBenchmarkVulcan_GithubAll6885193333 ns/op19894 B/op609 allocs/op
(1): Total Repetitions achieved in constant time, higher means more confident result
(2): Single Repetition Duration (ns/op), lower is better
(3): Heap Memory (B/op), lower is better
(4): Average Allocations per Repetition (allocs/op), lower is better
🔌 Middleware Ecosystem
Gin has a rich ecosystem of middleware for common web development needs. Explore community-contributed middleware:
gin-contrib - Official middleware collection including:
Authentication (JWT, Basic Auth, Sessions)
CORS, Rate limiting, Compression
Logging, Metrics, Tracing
Static file serving, Template engines
gin-gonic/contrib - Additional community middleware
🏢 Production Usage
Gin powers many high-traffic applications and services in production:
gorush - High-performance push notification server
fnproject - Container-native, serverless platform
photoprism - AI-powered personal photo management
lura - Ultra-performant API Gateway framework
picfit - Real-time image processing server
dkron - Distributed job scheduling system
🤝 Contributing
Gin is the work of hundreds of contributors from around the world. We welcome and appreciate your contributions! See the full list of contributors.
How to Contribute
🐛 Report bugs - Help us identify and fix issues
💡 Suggest features - Share your ideas for improvements
📝 Improve documentation - Help make our docs clearer
🔧 Submit code - Fix bugs or implement new features
🧪 Write tests - Improve our test coverage
Getting Started with Contributing
Check out our CONTRIBUTING.md for detailed guidelines
Join our community discussions and ask questions
All contributions are valued and help make Gin better for everyone!
On this page
- Gin Web Framework
- 📰 Gin 1.12.0 is now available!
- Getting Started
- Prerequisites
- Installation
- Your First Gin Application
- Next Steps
- 📚 Learning Resources
- 📖 Documentation
- API Reference
- User Guides
- Official Tutorials
- ⚡ Performance Benchmarks
- 🔌 Middleware Ecosystem
- 🏢 Production Usage
- 🤝 Contributing
- How to Contribute
- Getting Started with Contributing