Gin From Zero
Learn Go's most popular web framework: the engine and your first server, routing and route groups, binding and validating JSON, responses and rendering, middleware, building a full REST API, error handling and project structure, and testing and production. A thin, fast layer over net/http that you'll meet in most Go web jobs.
- What Gin Is & Your First Server Gin is a thin, fast layer over net/http: an engine holds your routes and a context handles each request. Install it, write a tiny server, run it, and meet the engine and context.
- Routing & Route Groups How Gin matches a request to a handler: HTTP methods, path and query params, wildcards, and route groups for versioning and shared prefixes — built on the tasks API.
- Binding & Validating Input Decode JSON, query strings, and URI params straight onto typed Go structs and validate them in one step with ShouldBind* and struct tags, so handlers stop poking at raw request data.
- Responses & Rendering Pick one render helper and one status code to answer a request: c.JSON for APIs, plus String, Data, File, and Redirect, HTML templates with auto-escaping, and serving static files.
- Middleware Middleware is a handler that runs around your handlers. Learn c.Next(), c.Abort(), passing data with c.Set/c.Get, the built-in Logger and Recovery, and writing your own.
- Building a REST API Assemble routing, binding, and responses into full CRUD for the tasks resource: an in-memory store guarded by a mutex, five handlers over one collection, wired to a versioned route group.
- Error Handling & Project Structure Make handlers thin translators between HTTP and your domain, return one consistent JSON error shape with c.Error and a middleware, map sentinel errors to status codes, and split the single-file tasks app into packages.
- Testing & Production Test a Gin app in-memory with net/http/httptest (no ports), structure it as a setupRouter() you build in main and tests, then ship it with ReleaseMode, real timeouts, and graceful shutdown.
- Where to Go Next You can build, structure, test, and ship a real Gin REST API. Now the honest map: Gin vs Echo, chi, Fiber, and net/http, the database layer, and what to build.