Code Explainers

Go code explainers

go
package security
 
import (
	"crypto/hmac"

Signing and verifying payloads with HMAC in Go

hmac cryptography authentication
Intermediate 5 steps
go
package handlers
 
import (
	"context"

Liveness vs readiness health checks in Gin

health-checks dependency-injection context-timeout
Intermediate 7 steps
go
package handlers
 
import (
	"net/http"

Custom query validation in Gin

validation query-binding deduplication
Intermediate 8 steps
go
package storage
 
import (
	"context"

A SQLite-backed order store in Go

database/sql sqlite error-wrapping
Intermediate 7 steps
go
package auth
 
import (
	"errors"

Hashing and verifying passwords with bcrypt in Go

password-hashing bcrypt error-handling
Intermediate 7 steps
go
package fsutil
 
import (
	"io/fs"

Walking a directory tree to find large files in Go

filesystem recursion closures
Intermediate 7 steps
go
package middleware
 
import (
	"log"

Per-IP rate limiting middleware in Gin

rate-limiting middleware concurrency
Intermediate 8 steps
go
func handleUpload(w http.ResponseWriter, r *http.Request) {
	if err := r.ParseMultipartForm(32 << 20); err != nil {
		http.Error(w, "failed to parse form: "+err.Error(), http.StatusBadRequest)
		return

Handling multi-file uploads in Go

multipart file-upload http-handler
Intermediate 9 steps
go
package render
 
import (
	"net/http"

How Gin renders MsgPack responses

serialization content-type interface-implementation
Intermediate 5 steps
go
package proxy
 
import (
	"log"

Building a hardened Go reverse proxy

reverse-proxy http timeouts
Intermediate 7 steps
go
package middleware
 
import (
	"net/http"

A per-IP rate limiter middleware in Gin

rate-limiting token-bucket middleware
Intermediate 8 steps
go
package tsvio
 
import (
	"bufio"

Reading and writing TSV records in Go

parsing io-streams error-handling
Intermediate 10 steps
go
package config
 
import (
	"fmt"

Loading and saving YAML config in Go

yaml struct-tags defaults
Intermediate 8 steps
go
package theme
 
import (
	"fmt"

Per-tenant HTML templates with Gin's renderer

multi-tenancy concurrency html-templates
Advanced 8 steps
go
package auth
 
import (
	"net/http"

Setting and reading secure session cookies in Go

cookies session-management security
Intermediate 6 steps
go
package middleware
 
import (
	"net/http"

A maintenance-mode gate in Gin

middleware atomic-flag concurrency
Intermediate 8 steps
go
func ServeVideo(c *gin.Context) {
	id := c.Param("id")
	video, err := videoRepo.FindByID(c.Request.Context(), id)
	if err != nil {

Streaming video files with Gin

http streaming range requests file serving
Intermediate 6 steps
go
package handler
 
type LineItem struct {
	SKU      string  `json:"sku" binding:"required,alphanum"`

Structured validation errors in Gin

validation json-binding error-handling
Intermediate 8 steps