Backend
Gin
A fast HTTP framework for Go with a router, middleware and convenient JSON handling.
What it is
Gin is a thin layer over net/http with a fast radix-tree router. It adds route groups, middleware, JSON binding and validation.
The framework is minimal: you choose the ORM and project structure. That is a familiar approach for Go developers.
A Go binary compiles to a single file, starts fast and uses little memory, so Gin is often chosen for microservices and APIs.
Use it when
- REST APIs and microservices in Go with a focus on speed.
- You need simple routes and middleware without a heavy framework.
- Small containers and fast cold starts.
Avoid it when
- You need a full stack with admin and ORM out of the box: Django, Rails, Laravel.
- For simple cases, the standard
net/httpin recent Go versions is enough.
Key concepts
- Context
*gin.Contextcarries the request, response and values between middleware.- Router group
- A group of routes with a shared prefix and middleware.
- Binding
- Parsing JSON or a form into a struct with tag-based validation.
- Middleware
- A function that calls
c.Next()orc.Abort().
Example
Interview questions
1. Why is Gin fast?
A radix-tree router with no allocations on the hot path and less overhead than large frameworks. Go itself also handles networking quickly.
2. How does middleware work in Gin?
It is a
gin.HandlerFuncrun before or after the handler.c.Next()passes control on,c.Abort()stops the chain.3. How do you validate input JSON?
Describe a struct with
binding:"required"tags and callc.ShouldBindJSON(&dto). A validation failure comes back as anerror.
Related technologies
- GoA simple compiled language with built-in concurrency for network services and infrastructure.
- PostgreSQLA powerful open source relational database with extensions, JSONB, full-text search and strong SQL support.
- gRPCA remote procedure call framework on HTTP/2 and Protocol Buffers for fast service-to-service communication.
Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).