---
name: gin
summary: "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."
language: Go
license: MIT
repo: https://github.com/gin-gonic/gin
source: https://opensources.dev/resource/gin
health: 100
---

# 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.

# Gin Web Framework

[![Build Status](https://github.com/gin-gonic/gin/actions/workflows/gin.yml/badge.svg?branch=master)](https://github.com/gin-gonic/gin/actions/workflows/gin.yml)
[![Trivy Security Scan](https://github.com/gin-gonic/gin/actions/workflows/trivy-scan.yml/badge.svg)](https://github.com/gin-gonic/gin/actions/workflows/trivy-scan.yml)
[![codecov](https://codecov.io/gh/gin-gonic/gin/branch/master/graph/badge.svg)](https://codecov.io/gh/gin-gonic/gin)
[![Go Report Card](https://goreportcard.com/badge/github.com/gin-gonic/gin)](https://goreportcard.com/report/github.com/gin-gonic/gin)
[![Go Reference](https://pkg.go.dev/badge/github.com/gin-gonic/gin?status.svg)](https://pkg.go.dev/github.com/gin-gonic/gin?tab=doc)
[![Sourcegraph](https://sourcegraph.com/github.com/gin-gonic/gin/-/badge.svg)](https://sourcegraph.com/github.com/gin-gonic/gin?badge)
[![Open Source Helpers](https://www.codetriage.com/gin-gonic/gin/badges/users.svg)](https://www.codetriage.com/gin-gonic/gin)
[![Release](https://img.shields.io/github/release/gin-gonic/gin.svg?style=flat-square)](https://github.com/gin-gonic/gin/releases)

## 📰 Gin 1.12.0 is now available!

We're excited to announce the release of [**Gin 1.12.0**](https://gin-gonic.com/en/blog/news/gin-1-12-0-release-announcement/)! This release brings new features, performance improvements, and important bug fixes. Check out the [release announcement](https://gin-gonic.com/en/blog/news/gin-1-12-0-release-announcement/) on our official blog for the full details.

---

Gin is a high-performance HTTP web framework written in [Go](https://go.dev/). It provides a Martini-like API but with significantly better performance—up to 40 times faster—thanks to [httprouter](https://github.com/julienschmidt/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

- **Go version**: Gin requires [Go](https://go.dev/) version [1.25](https://go.dev/doc/devel/release#go1.25.0) or above
- **Basic Go knowledge**: Familiarity with Go syntax and package management is helpful

### Installation

With [Go's module support](https://go.dev/wiki/Modules#how-to-use-modules), simply import Gin in your code and Go will automatically fetch it during build:

```go
import "github.com/gin-gonic/gin"
```

### Your First Gin Application

Here's a complete example that demonstrates Gin's simplicity:

```go
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:
   ```sh
   go run main.go
   ```
3. Open your browser and visit [`http://localhost:8080/ping`](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

### Next Steps

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

### 📚 Learning Resources

- [**Gin Quick Start Guide**](docs/doc.md) - Comprehensive tutorial with API examples and build configurations
- [**Example Repository**](https://github.com/gin-gonic/examples) - 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**](https://pkg.go.dev/github.com/gin-gonic/gin) - Complete API reference with examples

### User Guides

The comprehensive documentation is available on [gin-gonic.com](https://gin-gonic.com) in multiple languages:

- [English](https://gin-gonic.com/en/docs/) | [简体中文](https://gin-gonic.com/zh-cn/docs/) | [繁體中文](https://gin-gonic.com/zh-tw/docs/)
- [日本語](https://gin-gonic.com/ja/docs/) | [한국어](https://gin-gonic.com/ko-kr/docs/) | [Español](https://gin-gonic.com/es/docs/)
- [Turkish](https://gin-gonic.com/tr/docs/) | [Persian](https://gin-gonic.com/fa/docs/) | [Português](https://gin-gonic.com/pt/docs/)
- [Russian](https://gin-gonic.com/ru/docs/) | [Indonesian](https://gin-gonic.com/id/docs/)

### Official Tutorials

- [Go.dev Tutorial: Developing a RESTful API with Go and Gin](https://go.dev/doc/tutorial/web-service-gin)

## ⚡ Performance Benchmarks

Gin demonstrates exceptional performance compared to other Go web frameworks. It uses a custom version of [HttpRouter](https://github.com/julienschmidt/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_GithubAll**43550****27364 ns/op****0 B/op****0 allocs/op**BenchmarkAce_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**](https://github.com/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**](https://github.com/gin-gonic/contrib) - Additional community middleware

## 🏢 Production Usage

Gin powers many high-traffic applications and services in production:

- [**gorush**](https://github.com/appleboy/gorush) - High-performance push notification server
- [**fnproject**](https://github.com/fnproject/fn) - Container-native, serverless platform
- [**photoprism**](https://github.com/photoprism/photoprism) - AI-powered personal photo management
- [**lura**](https://github.com/luraproject/lura) - Ultra-performant API Gateway framework
- [**picfit**](https://github.com/thoas/picfit) - Real-time image processing server
- [**dkron**](https://github.com/distribworks/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](https://github.com/gin-gonic/gin/graphs/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

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!**
