API Reference

Gin

High-performance HTTP web framework for Go with a martini-like API and 40x faster routing.

Official Documentation ↗
CompatibilityThis documentation covers version v1.10. Check the official docs for the latest API surface.

Installation

gogo get github.com/gin-gonic/gin

Methods

Gin is a high-performance HTTP web framework written in Go. It features a martini-like API with much better performance, thanks to a custom radix-tree router and lightweight request context.

Key Features

  • Fast: Radix-tree routing with low allocations
  • Middleware: Global and per-group middleware chains
  • Binding: JSON, form, URI, and header binding with validation
  • Routing: Groups, parameters, and wildcards
  • Rendering: JSON, XML, HTML, and custom renderers

FAQ

Why is Gin so fast?
Gin uses a custom HttpRouter based on a radix tree for O(log n) route lookup with minimal allocations. Combined with its lightweight context, it handles high throughput with low memory per request.
How do I handle validation in Gin?
Use binding tags on structs (binding:required, min, max) and call c.ShouldBindJSON or c.ShouldBind. Gin uses go-playground/validator under the hood for rich, tag-based validation.
Can I use Gin with middleware like CORS?
Yes. Use github.com/gin-contrib/cors and call r.Use(cors.Default()) or a configured cors.Config. Many common middlewares live in the gin-contrib organization.