A lightning-fast HTTP web framework for Go. Express-style routing with middleware — small surface area, huge performance, the most popular Go web framework.
← Back to Server Sidefunc(c *gin.Context) — context wraps the request, response, params, and middleware state.v1 := r.Group("/api/v1")).package main import "github.com/gin-gonic/gin" type Product struct { Name string `json:"name" binding:"required"` Price float64 `json:"price" binding:"required,gt=0"` } func main() { r := gin.Default() r.GET("/products", func(c *gin.Context) { c.JSON(200, gin.H{"items": []string{}}) }) r.POST("/products", func(c *gin.Context) { var p Product if err := c.ShouldBindJSON(&p); err != nil { c.JSON(400, gin.H{"error": err.Error()}) return } c.JSON(201, p) }) r.Run(":8080") }
Radix-tree router from httprouter — extremely fast, predictable URL matching. Group routes by prefix and stack middleware per group.
Struct tags drive JSON / form / query / URI binding plus validation via go-playground/validator. binding:"required,email" just works.
| Middleware | Purpose |
|---|---|
| gin.Logger / Recovery | Logging & panic recovery (default). |
| gin-contrib/cors | CORS handling. |
| gin-contrib/sessions | Sessions backed by cookie / Redis / Memcached. |
| gin-contrib/secure | Security headers. |
| otelgin | OpenTelemetry tracing. |
net/http router.net/http routing; plain stdlib is now viable for many APIs.net/http patterns.Microservices that need to scale horizontally.
Tiny binaries deploy fast on Kubernetes & Lambda.
Build infrastructure tooling alongside Kubernetes / Docker.
Lightweight edge services in front of heavier backends.