Skip to content
Oeiuwq Faith Blog OpenSource Porfolio

gin-gonic/gin

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.

gin-gonic/gin.json
{
"createdAt": "2014-06-16T23:57:25Z",
"defaultBranch": "master",
"description": "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.",
"fullName": "gin-gonic/gin",
"homepage": "https://gin-gonic.com/",
"language": "Go",
"name": "gin",
"pushedAt": "2025-11-23T04:20:48Z",
"stargazersCount": 87141,
"topics": [
"framework",
"gin",
"go",
"middleware",
"performance",
"router",
"server"
],
"updatedAt": "2025-11-26T01:23:02Z",
"url": "https://github.com/gin-gonic/gin"
}

Build Status Trivy Security Scan codecov Go Report Card Go Reference Sourcegraph Open Source Helpers Release

Read about the latest features and improvements in Gin 1.11.0 on our official blog.


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
  • Go version: Gin requires Go version 1.24 or above
  • Basic Go knowledge: Familiarity with Go syntax and package management is helpful

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"

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:

  1. Save the code above as main.go

  2. Run the application:

    Terminal window
    go run main.go
  3. Open your browser and visit http://localhost:8080/ping

  4. You 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

After running your first Gin application, explore these resources to learn more:

  • [Gin Quick Start Guide]!(docs/doc.md) - 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

The comprehensive documentation is available on gin-gonic.com in multiple languages:

Gin demonstrates exceptional performance compared to other Go web frameworks. It uses a custom version of HttpRouter for maximum efficiency. [View detailed benchmarks →]!(/BENCHMARKS.md)

Gin vs. Other Go Frameworks (GitHub API routing benchmark):

Benchmark name(1)(2)(3)(4)
BenchmarkGin_GithubAll4355027364 ns/op0 B/op0 allocs/op
BenchmarkAce_GithubAll4054329670 ns/op0 B/op0 allocs/op
BenchmarkAero_GithubAll5763220648 ns/op0 B/op0 allocs/op
BenchmarkBear_GithubAll9234216179 ns/op86448 B/op943 allocs/op
BenchmarkBeego_GithubAll7407243496 ns/op71456 B/op609 allocs/op
BenchmarkBone_GithubAll4202922835 ns/op720160 B/op8620 allocs/op
BenchmarkChi_GithubAll7620238331 ns/op87696 B/op609 allocs/op
BenchmarkDenco_GithubAll1835564494 ns/op20224 B/op167 allocs/op
BenchmarkEcho_GithubAll3125138479 ns/op0 B/op0 allocs/op
BenchmarkGocraftWeb_GithubAll4117300062 ns/op131656 B/op1686 allocs/op
BenchmarkGoji_GithubAll3274416158 ns/op56112 B/op334 allocs/op
BenchmarkGojiv2_GithubAll1402870518 ns/op352720 B/op4321 allocs/op
BenchmarkGoJsonRest_GithubAll2976401507 ns/op134371 B/op2737 allocs/op
BenchmarkGoRestful_GithubAll4102913158 ns/op910144 B/op2938 allocs/op
BenchmarkGorillaMux_GithubAll3463384987 ns/op251650 B/op1994 allocs/op
BenchmarkGowwwRouter_GithubAll10000143025 ns/op72144 B/op501 allocs/op
BenchmarkHttpRouter_GithubAll5593821360 ns/op0 B/op0 allocs/op
BenchmarkHttpTreeMux_GithubAll10000153944 ns/op65856 B/op671 allocs/op
BenchmarkKocha_GithubAll10000106315 ns/op23304 B/op843 allocs/op
BenchmarkLARS_GithubAll4777925084 ns/op0 B/op0 allocs/op
BenchmarkMacaron_GithubAll3266371907 ns/op149409 B/op1624 allocs/op
BenchmarkMartini_GithubAll3313444706 ns/op226551 B/op2325 allocs/op
BenchmarkPat_GithubAll2734381818 ns/op1483152 B/op26963 allocs/op
BenchmarkPossum_GithubAll10000164367 ns/op84448 B/op609 allocs/op
BenchmarkR2router_GithubAll10000160220 ns/op77328 B/op979 allocs/op
BenchmarkRivet_GithubAll1462582453 ns/op16272 B/op167 allocs/op
BenchmarkTango_GithubAll6255279611 ns/op63826 B/op1618 allocs/op
BenchmarkTigerTonic_GithubAll2008687874 ns/op193856 B/op4474 allocs/op
BenchmarkTraffic_GithubAll3553478508 ns/op820744 B/op14114 allocs/op
BenchmarkVulcan_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

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

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

Gin is the work of hundreds of contributors from around the world. We welcome and appreciate your contributions!

  • 🐛 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
  1. Check out our [CONTRIBUTING.md]!(CONTRIBUTING.md) for detailed guidelines
  2. Join our community discussions and ask questions

All contributions are valued and help make Gin better for everyone!