go

go
package store

import (
  "context"
  "time"

pgxpool initialization with max connections and statement timeout

go postgres pgx
by Leah Thompson 1 tab
go
package api

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

Consistent JSON responses (content-type + error envelopes)

go http json
by Leah Thompson 1 tab
go
package middleware

import (
  "net/http"
  "sync/atomic"
)

Track in-flight requests with atomic counters

go observability concurrency
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
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 retry

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

Exponential backoff with jitter for retries

go reliability retry
by Leah Thompson 1 tab
go
package config

import (
  "io"

  "gopkg.in/yaml.v3"

Safe YAML decoding (KnownFields) for config files

go config yaml
by Leah Thompson 1 tab
go
package api

import "strings"

type Issue struct {
  Field   string `json:"field"`

JSON schema-ish validation with custom error details

go api json
by Leah Thompson 1 tab
go
package ratelimit

import (
	"sync"
	"time"
)

Token Bucket Rate-Limiting Middleware for a Go net/http API

go net-http middleware
by codesnips 4 tabs
go
package api

import "net/http"

func ETag(w http.ResponseWriter, r *http.Request, etag string) bool {
  w.Header().Set("ETag", etag)

ETag handling for conditional GETs (cheap caching)

go http caching
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 config

import (
  "fmt"
  "os"
  "strconv"

Robust environment parsing for bool/int with explicit defaults

go config reliability
by Leah Thompson 1 tab