Code Explainers
Gin code explainers
go
package handlers import ( "errors"
Turning Gin binding errors into field messages
input validation
struct tags
error handling
Intermediate
9 steps
go
package middleware import ( "strconv"
Instrumenting a Gin API with Prometheus
middleware
observability
metrics
Intermediate
6 steps
go
type SensorReading struct { DeviceID string `json:"device_id" binding:"required"` Temperature float64 `json:"temperature"` RecordedAt time.Time `json:"recorded_at" binding:"required"`
Streaming NDJSON ingestion in Gin
streaming
batching
json-decoding
Advanced
10 steps
go
package handlers import ( "net/http"
Struct-level validation for partial updates in Gin
validation
struct-tags
partial-update
Intermediate
7 steps
go
package handlers import ( "net/http"
Content negotiation in Gin handlers
content-negotiation
struct-tags
rest-api
Intermediate
4 steps
go
package handlers type BookURI struct { Collection string `uri:"collection" binding:"required,alphanum"`
Validating URI params in a Gin handler
input validation
struct binding
error handling
Intermediate
7 steps
go
package middleware import ( "crypto/subtle"
Building an API-key middleware in Gin
middleware
authentication
dependency-injection
Intermediate
5 steps
go
package api func RegisterRoutes(r *gin.Engine, deps *Dependencies) { r.GET("/health", func(c *gin.Context) {
Layering route groups and middleware in Gin
routing
middleware
authentication
Intermediate
8 steps
go
package middleware import ( "compress/gzip"
How gzip response compression works in Gin
middleware
compression
http
Intermediate
8 steps
go
package middleware import ( "context"
Correlation ID tracing middleware in Gin
middleware
request tracing
structured logging
Intermediate
7 steps
go
package middleware import ( "bytes"
Verifying webhook HMAC signatures in Gin
hmac
middleware
webhooks
Intermediate
7 steps
go
package handlers import ( "fmt"
Handling secure file uploads in Gin
file-upload
validation
security
Intermediate
7 steps
go
package server import ( "net/http"
Serving a single-page app with Gin
static-files
spa
routing
Intermediate
7 steps
go
package handlers import ( "fmt"
Handling multipart profile uploads in Gin
form binding
file upload
validation
Intermediate
7 steps
go
package middleware import ( "time"
Building a request logger middleware in Gin
middleware
structured-logging
closures
Intermediate
6 steps
go
func UploadFiles(c *gin.Context) { form, err := c.MultipartForm() if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": "invalid multipart form"})
Handling multi-file uploads in Gin
file-upload
multipart
validation
Intermediate
8 steps
go
package auth import ( "net/http"
Building a JWT auth middleware in Gin
middleware
jwt
authentication
Intermediate
7 steps
go
func RecoveryHandler(logger *zap.Logger) gin.HandlerFunc { return gin.CustomRecovery(func(c *gin.Context, recovered any) { var brokenPipe bool if ne, ok := recovered.(*net.OpError); ok {
A panic-recovery middleware in Gin
middleware
panic-recovery
structured-logging
Intermediate
6 steps