What is Gin?
Gin is an HTTP web framework for the Go programming language, maintained in the gin-gonic organization on GitHub and released under the MIT license. The project describes it as a framework with a Martini-like API and performance up to 40 times faster than Martini, a result it credits to httprouter; Gin uses its own customized version of that router. The README names REST APIs, web applications and microservices as its main use, and the introduction lists a radix tree router without reflection, middleware chains, panic recovery, JSON validation, route groups, error collection and built-in rendering as its core features.
Gin is distributed as a Go module, github.com/gin-gonic/gin. The quickstart adds it with go get -u github.com/gin-gonic/gin inside a module created with go mod init, and the README notes that a plain import is enough for Go to fetch it during the build. There are no binaries, installers or hosted service: Gin is compiled into the application that uses it. The API reference is published on pkg.go.dev, and the user guide on gin-gonic.com is available in English, Simplified and Traditional Chinese, Japanese, Korean, Spanish, Turkish, Persian, Portuguese, Russian, Indonesian and Arabic. The Go project's own tutorial, Developing a RESTful API with Go and Gin, uses Gin as its example framework.
The current release is Gin v1.12.0, published on February 28, 2026. According to the release announcement, it adds BSON rendering, the context helpers GetError, GetErrorSlice and Delete, encoding.UnmarshalText support in URI and query binding, an engine option to route on the escaped request path, Protocol Buffers in content negotiation and colored latency in the default logger. It also reduces allocations in the router tree, lets the logger skip query strings, always trusts X-Forwarded-For headers on Unix socket connections, and fixes ClientIP handling for multiple X-Forwarded-For headers and a file descriptor leak in RunFd. The previous release, v1.11.0 of September 2025, introduced experimental HTTP/3 support through quic-go and extended form binding.
Gin v1.12.0 requires Go 1.25 or later; the README, the documentation and the release notes state this minimum. On the master branch, which is not yet part of a release, the go.mod file declares Go 1.26.0, the Run methods set a default ReadHeaderTimeout on the underlying http.Server, and Any also registers the HTTP QUERY method. The v1 API is described by the project as frozen, so that new releases do not break existing code.
Some functions sit outside the core module. WebSocket support is not built in; the documentation shows an integration with gorilla/websocket. Middleware for CORS, sessions, JWT, rate limiting, compression, metrics and tracing lives in the separate gin-contrib organization, and automatic Let's Encrypt certificates come from the gin-gonic/autotls package. Gin itself does not include an ORM or a database layer; the database guide shows Go's database/sql package used alongside it. Other frameworks on iThub are grouped under Web Frameworks & UI Libraries.
Key capabilities
- Installation as a Go module The quickstart creates a module with
go mod initand adds Gin withgo get -u github.com/gin-gonic/gin. With module support, importinggithub.com/gin-gonic/ginis enough for the Go toolchain to fetch it during the build. Gin v1.12.0 requires Go 1.25 or later, and the result is a regular Go binary with no separate runtime. - Default and empty engines
gin.Default()returns a router with the Logger and Recovery middleware already attached, whilegin.New()returns an engine without middleware.router.Run()listens on 0.0.0.0:8080 by default, or on the port in thePORTenvironment variable, and also accepts an explicit address such as:8080. - Radix tree router Routing uses a radix tree based on a customized version of httprouter, with no reflection and no heap allocations during route matching according to the project. Handlers can be registered for each HTTP method, with path parameters, wildcard segments, query strings and redirects documented in the routing section. Since v1.12.0 an engine option can route on the escaped request path.
- Route groups
router.Group("/v1")creates a group that shares a path prefix and middleware, for example to separate API versions or routes that require authorization. The introduction states that groups can be nested without limit and without degrading performance. - Middleware chain A middleware has the same signature as a handler,
gin.HandlerFunc, and callsc.Next()to pass control on, so code before and after that call runs around the handler. Middleware can be attached globally, to a group or to a single route, and the broader scope runs first. Built-in middleware includes Logger, Recovery and BasicAuth. - Panic recovery The Recovery middleware catches a panic raised during a request and returns a 500 response instead of stopping the server.
gin.CustomRecovery()accepts a custom handler for the recovered value, and v1.12.0 suppresseshttp.ErrAbortHandlerin recovery and reads stack traces more efficiently. - Binding and validation Request data can be bound into structs from JSON, XML, YAML, TOML, URL-encoded and multipart forms, query strings, URI parameters and headers, using struct tags. Validation rules go in the
bindingtag with go-playground/validator syntax, and custom validators can be registered. TheBindfamily aborts with a 400 response on error, whileShouldBindreturns the error to the handler, as explained in the binding guide. - Response rendering
*gin.Contextrenders JSON, XML, YAML, TOML, ProtoBuf and, since v1.12.0, BSON, setting the content type automatically. JSON variants include SecureJSON, JSONP, AsciiJSON and PureJSON. HTML rendering uses Go templates, supports multiple template sets and can embed templates into a single binary. - Files, uploads and streaming
Static,StaticFileandStaticFSserve directories, single files and embedded file systems. Single and multiple file uploads useFormFileandMultipartForm, with a documented way to limit upload size, and responses can be streamed from anyio.Readeror sent as file attachments. - Error collection Errors raised while handling a request can be attached to the context and processed centrally, for example by middleware that writes them to a log or a database. Version 1.12.0 adds
GetErrorandGetErrorSlicefor type-safe retrieval of values from the context. - Logging options The default logger prints method, path, status and latency, with latency colored since v1.12.0.
LoggerWithConfigcan skip paths such as health checks, use a custom format, control colors, write to a file and omit query strings. The documentation also covers structured logging. - Server configuration
gin.Engineimplementshttp.Handler, so it can be passed to a standardnet/http.Serverto set read and write timeouts, header limits and TLS. The server configuration section covers graceful shutdown, running several engines on different ports, HTTP/2 server push, cookies and automatic Let's Encrypt certificates through gin-gonic/autotls. Experimental HTTP/3 support through quic-go was added in v1.11.0. - Trusted proxies and client IP
SetTrustedProxiesdefines which IPv4 or IPv6 addresses and CIDR ranges may set client IP headers such as X-Forwarded-For. The trusted proxies page states that Gin trusts all proxies by default and that this is not safe.TrustedPlatformreads the client IP from a CDN header, with predefined values such as Google App Engine and Cloudflare. - Run modes and environment variables
GIN_MODEaccepts debug, release or test, and the same can be set in code withgin.SetMode. Debug mode prints route registration and other diagnostics, and test mode suppresses them.PORTsets the listen port whenRun()is called without arguments. - JSON encoder build tags Build tags swap the JSON implementation at compile time without code changes:
go_jsonuses go-json,jsoniteruses json-iterator andsonic avxuses ByteDance sonic. The build tag guide notes that sonic requires a CPU with AVX instructions and does not run on ARM, and that only one JSON tag should be set at a time. Thenomsgpacktag removes MsgPack rendering. - Testing with httptest The testing guide uses Go's
net/http/httptestpackage: a test builds the router, sends a request throughrouter.ServeHTTPwith a response recorder and checks status and body. Callinggin.SetMode(gin.TestMode), for example inTestMain, keeps route debug logs out of test output. - gin-contrib middleware The gin-contrib organization maintains middleware outside the core module, including CORS, sessions, CSRF protection, JWT, rate limiting, compression, OpenMetrics and Prometheus metrics, tracing, static files and template engines. Each is a separate Go module added with
go get, and the gin-gonic/contrib repository collects further community middleware. - Published benchmark data The benchmarks page reports results collected on March 15, 2026 with Gin v1.12.0 and Go 1.25.8 on an Apple M4 Pro, using the Go HTTP router benchmark suite. Routing all 203 GitHub API routes took 9,944 ns per operation with 0 bytes and 0 allocations, first among 12 routers in that table, while HttpRouter and HttpTreeMux ranked ahead of Gin for 157 static routes. The page adds that Fiber results use a different request type and should be compared with care.
Where Gin fits
JSON REST APIs and microservices
The README and the Go project's RESTful API tutorial build HTTP endpoints that read and return JSON. A typical service registers handlers on gin.Default(), groups versioned endpoints under prefixes such as /v1, binds request bodies into structs and returns responses with c.JSON. Projects listed on the official users page include the gorush push notification server, the lura API gateway and the photoprism photo application.
Validating incoming requests
The binding guide describes declaring a struct with json, form, uri or header tags and rules in the binding tag, such as required. ShouldBind chooses a decoder from the Content-Type header and returns validation errors to the handler, which can then send its own error response. Separate pages cover default values, array collection formats, custom unmarshalers and binding the body into more than one struct.
Server-rendered pages and static assets
For web applications, LoadHTMLGlob or LoadHTMLFiles load Go templates that handlers render with c.HTML, and static directories are mounted with Static or an embedded file system with StaticFS. The rendering section documents multiple template sets and embedding templates in the compiled binary, so the application can ship as a single file.
Running behind a reverse proxy or CDN
When a Gin service sits behind Nginx, HAProxy, a load balancer or a CDN, ClientIP() depends on the trusted proxy settings. The documentation shows SetTrustedProxies with the proxy addresses, SetTrustedProxies(nil) when no proxy is used, and TrustedPlatform for CDNs that send the client address in their own header. The security guide adds CORS, CSRF, rate limiting and security header middleware.
Observability and testing
The metrics page exposes a /metrics endpoint for Prometheus through gin-contrib/openmetrics, or with a custom middleware based on prometheus/client_golang that labels requests by c.FullPath() to keep label cardinality low. Handlers are tested in process with httptest, without opening a network port, and the FAQ describes live reload during development with the Air tool.
Deployment
The deployment page links guides for Railway, Seenode, Koyeb, Qovery, Render and Google App Engine, and also describes self-hosted deployment configured through PORT, GIN_MODE and code. For self-hosted servers the documentation shows a custom http.Server with timeouts, graceful shutdown and automatic TLS through gin-gonic/autotls, which requires ports 80 and 443 to be reachable from the internet.
Install
go get -u github.com/gin-gonic/ginReviews of Gin
Be the first to share your experience with Gin.
Write a review
Loading review form…
Found Gin useful? Upvote it todayYour vote helps other IT teams find it in the daily ranking.

