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 deps

import (
  "net/http"
  "time"

HTTP client middleware via RoundTripper (headers + timing)

go http client
by Leah Thompson 1 tab
go
package admin

import (
  "net/http"
  "net/http/pprof"
)

Admin-only pprof endpoint with basic auth

go observability pprof
by Leah Thompson 1 tab
go
package api

import (
  "net/http"
  "runtime/debug"
)

Expose build metadata for debugging deploys

go observability build
by Leah Thompson 1 tab
go
package observability

import (
  "context"
  "log/slog"
  "os"

Request-scoped slog logger with JSON output (Go 1.21+)

go logging observability
by Leah Thompson 1 tab
go
package middleware

import (
  "net/http"
)

CORS allowlist middleware (no wildcard surprises)

go http security
by Leah Thompson 1 tab
go
package webhooks

import (
  "bytes"
  "crypto/hmac"
  "crypto/sha256"

Webhook signature verification with HMAC (timing-safe compare)

go security http
by Leah Thompson 1 tab
go
package hotpath

import "testing"

func BenchmarkParse(b *testing.B) {
  b.ReportAllocs()

Benchmarking hot paths (allocs and throughput)

go performance benchmarking
by Leah Thompson 1 tab
go
package api_test

import (
  "encoding/json"
  "net/http"
  "net/http/httptest"

Table-driven tests for HTTP handlers with httptest

go testing http
by Leah Thompson 1 tab
go
package flags

import (
  "context"
  "encoding/json"
  "sync/atomic"

Feature flag snapshot with periodic refresh and atomic reads

go config reliability
by Leah Thompson 1 tab
go
package files

import (
  "context"
  "time"

Presigned S3 upload URLs (AWS SDK v2)

go aws s3
by Leah Thompson 1 tab
go
package store

import (
  "context"

  "github.com/jackc/pgx/v5"

Row-level locking with SELECT ... FOR UPDATE in a transaction

go postgres transactions
by Leah Thompson 1 tab
sql
ALTER TABLE documents ADD COLUMN version BIGINT NOT NULL DEFAULT 0;

Optimistic locking with a version column

go postgres sql
by Leah Thompson 2 tabs