go

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
go
package middleware

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

Panic recovery middleware that fails closed and logs context

go http middleware
by Leah Thompson 1 tab
go
package pipeline

import "context"

func generate(ctx context.Context, nums ...int) <-chan int {
	out := make(chan int)

Fan-Out/Fan-In Pipeline With Channels and Context Cancellation in Go

go concurrency channels
by codesnips 3 tabs
go
package paging

import (
  "encoding/base64"
  "encoding/json"
  "time"

Cursor pagination: opaque tokens with stable ordering

go api pagination
by Leah Thompson 1 tab
go
package session

import (
	"crypto/hmac"
	"crypto/sha256"
	"encoding/base64"

Stateless Session Cookies Signed and Verified With HMAC in Go

go security cookies
by codesnips 3 tabs
go
package web

import (
  "bytes"
  "html/template"
  "net/http"

Template rendering with html/template and strict escaping

go templates http
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 feed

import "time"

type Event struct {
	ID        string    `json:"id"`

Stream and Decode Newline-Delimited JSON (NDJSON) from an HTTP Response Body in Go

go ndjson streaming
by codesnips 3 tabs
go
package pool

import "context"

type Job func(ctx context.Context) error

Bounded worker pool with backpressure

go concurrency worker-pool
by Leah Thompson 1 tab
go
package metrics

import (
  "net/http"
  "strconv"
  "time"

Prometheus metrics middleware capturing status + duration

go prometheus metrics
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 export

import (
	"encoding/csv"
	"log"
	"net/http"

Streaming Large CSV Exports in Go Without Buffering the Whole File

go http csv
by codesnips 3 tabs