Leah Thompson

78 code snips · on codesnips 6 months

Go backend engineer sharing production-grade patterns for APIs, concurrency, and data systems. I focus on reliability: timeouts, idempotency, observability, and clean service...

go
package cache

import (
  "context"

  "github.com/redis/go-redis/v9"

Redis Pub/Sub subscriber with reconnect-friendly loop

go redis pubsub
by Leah Thompson 1 tab
go
package store

import (
  "context"
  "database/sql"
)

sqlc transaction wrapper that keeps call sites clean

go sql postgres
by Leah Thompson 1 tab
go
package events

import "encoding/json"

type Envelope struct {
  Type    string          `json:"type"`

Store unstructured JSON safely with json.RawMessage

go json events
by Leah Thompson 1 tab
go
package api

import (
  "net/http"
  "strings"
)

Enforce JSON Content-Type and method early in handlers

go http api
by Leah Thompson 1 tab
go
package middleware

import (
  "net"
  "net/http"
  "net/netip"

CIDR allowlist middleware using netip (trust boundary explicit)

go http security
by Leah Thompson 1 tab
go
package middleware

import (
  "net/http"

  "golang.org/x/time/rate"

Inbound rate limiting middleware with token bucket

go http rate-limit
by Leah Thompson 1 tab
go
package cache

import (
  "context"
  "sync/atomic"
  "time"

Context-aware cache refresh with atomic.Pointer (Go 1.19+)

go concurrency cache
by Leah Thompson 1 tab
go
package observability

import (
  "time"

  "go.uber.org/zap"

Sampling logs to reduce noise during high-QPS incidents

go logging observability
by Leah Thompson 1 tab
go
package deps

import "sync"

type Lazy[T any] struct {
  once sync.Once

Lazy init of expensive clients with sync.Once

go concurrency sync
by Leah Thompson 1 tab
go
package debughttp

import (
  "context"
  "crypto/tls"
  "net/http"

HTTPtrace to debug DNS/connect/TLS timing in production-like runs

go http client
by Leah Thompson 1 tab
go
package migrate

import (
  "context"

  "github.com/jackc/pgx/v5/pgxpool"

Run database migrations on startup (with a guard)

go postgres migrations
by Leah Thompson 1 tab
go
package store

import (
  "context"
  "database/sql"
)

db/sql prepared statements with context and explicit Close

go sql postgres
by Leah Thompson 1 tab