go

go
        package api

        import (
          "context"
          "crypto/rand"
          "encoding/hex"

HTTP handler with timeouts, request IDs, and context cancellation

go http context
by Leah Thompson 2 tabs
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 (
  "io"
  "net/http"
)

Content sniffing for uploads (don't trust the header)

go http uploads
by Leah Thompson 1 tab
go
package api

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

WriteJSON helper with consistent headers and status

go http json
by Leah Thompson 1 tab
go
package main

import (
  "context"
  "log"
  "net/http"

Graceful shutdown: draining HTTP + background workers

go http shutdown
by Leah Thompson 1 tab
go
package main

import (
  "context"
  "net/http"
  "time"

HTTP server timeouts that prevent slowloris and stuck connections

go http reliability
by Leah Thompson 1 tab
go
package service

import (
  "context"

  "golang.org/x/sync/errgroup"

Fan-out with errgroup and shared cancellation

go concurrency context
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 middleware

import (
  "net/http"

  "go.uber.org/zap"

Panic recovery middleware for HTTP servers

go http middleware
by Leah Thompson 1 tab
go
package jobs

import (
  "context"
  "math/rand"
  "time"

Robfig cron jobs with context cancellation and jitter

go cron background-jobs
by Leah Thompson 1 tab
go
package domain

import (
  "errors"
  "fmt"
)

Error wrapping that stays inspectable with errors.Is and errors.As

go errors api
by Leah Thompson 1 tab