Code Explainers
Go code explainers
go
package handlers import ( "encoding/json"
Parsing search query params in a Go handler
http-handlers
input-validation
defaults
Intermediate
7 steps
go
package middleware import ( "bytes"
Idempotent requests in Gin with Redis
idempotency
caching
middleware
Advanced
10 steps
go
package middleware import ( "context"
A deadline-enforcing HTTP middleware in Go
middleware
context
goroutines
Advanced
7 steps
go
package logbuffer import ( "bufio"
A buffered logger with background flushing in Go
concurrency
buffering
context
Intermediate
8 steps
go
package handler import ( "net/http"
Custom time validation in Gin
validation
request-binding
struct-tags
Intermediate
8 steps
go
package middleware import ( "net/http"
Localized validation errors in Gin
middleware
internationalization
validation
Intermediate
8 steps
go
func ListProducts(c *gin.Context) { allowed := map[string]string{ "category": "category", "brand": "brand",
Safe query filtering in a Gin handler
input-validation
whitelisting
query-building
Intermediate
7 steps
go
func (h *ExportHandler) BulkExport(c *gin.Context) { projectID := c.Param("projectID") reports, err := h.reports.ListByProject(c.Request.Context(), projectID)
Streaming a ZIP download in Gin
streaming
zip-archive
http-headers
Intermediate
8 steps
go
package middleware import ( "crypto/sha256"
Deduplicating concurrent requests in Gin
singleflight
request-coalescing
middleware
Advanced
8 steps
go
package health import ( "context"
Building a health check endpoint in Go
health-check
context-timeout
dependency-probing
Intermediate
8 steps
go
package email import ( "errors"
Normalizing and deduping email addresses in Go
validation
normalization
deduplication
Intermediate
8 steps
go
type PostCursor struct { CreatedAt time.Time ID int64 }
Keyset pagination with cursors in Go
pagination
keyset-cursor
database
Intermediate
8 steps
go
package config import ( "fmt"
Parsing timeout config in Go
configuration
validation
error-wrapping
Intermediate
7 steps
go
func (h *WebhookHandler) HandleBatch(c *gin.Context) { var payload BatchWebhookPayload if err := c.ShouldBindJSON(&payload); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": "invalid payload"})
Handling batched webhooks in Gin
webhooks
signature-verification
job-queue
Intermediate
7 steps
go
package config import "time"
The functional options pattern in Go
functional-options
closures
immutability
Intermediate
7 steps
go
package admin import ( "net/http"
Building a protected admin area in Gin
routing
middleware
authentication
Intermediate
6 steps
go
package middleware import ( "errors"
Capping request body size in Gin
middleware
request limits
error handling
Intermediate
5 steps
go
package batch import "fmt"
Splitting a slice into batches in Go
generics
slices
error-handling
Intermediate
6 steps