go

go
package feed

import "time"

type Post struct {
	ID        int64

Batch-Load Related Rows with a Single IN Query to Avoid N+1

go sql postgres
by codesnips 3 tabs
go
package cleanup

import "errors"

func CloseAll(closers ...func() error) error {
  var errs []error

errors.Join for cleanup (surface multiple close failures)

go errors reliability
by Leah Thompson 1 tab
go
package health

import (
	"context"
	"sync"
	"time"

Concurrent Readiness Health Check Endpoint in Go with Timeouts

go health-check readiness
by codesnips 3 tabs
go
package logctx

import (
	"context"
	"log/slog"
)

Request-Scoped Structured Logging with slog and Context in Go

go logging slog
by codesnips 3 tabs
go
package authtransport

import (
	"errors"
	"net/http"
)

Injecting Auth Headers via a Custom http.RoundTripper Decorator in Go

go http middleware
by codesnips 3 tabs
go
package limit

import (
  "context"

  "golang.org/x/sync/semaphore"

Concurrency limiting with a context-aware semaphore

go concurrency context
by Leah Thompson 1 tab
go
package web

import (
	"embed"
	"io/fs"
)

Serve Embedded Static Assets with embed.FS and Cache Headers in Go

go embed static-assets
by codesnips 3 tabs
go
package main

import (
	"log"
	"net/http"
	"time"

Serving Partial Video Content with HTTP Range Requests in Go

go http range-requests
by codesnips 3 tabs
go
package apiclient

import (
	"context"
	"fmt"
	"io"

Sharing a golang.org/x/time/rate Limiter Across Goroutines for Outbound API Calls

go rate-limiting concurrency
by codesnips 3 tabs
go
package fetch

import (
	"context"
	"net/http"

Bounded Fan-Out With Worker Pool, errgroup, and Result Collection in Go

go concurrency goroutines
by codesnips 3 tabs
go
package hub

type Hub struct {
	subscribers map[*Subscriber]struct{}
	broadcast   chan []byte
	register    chan registration

Concurrent Fan-Out Event Hub With Non-Blocking Broadcast in Go

go concurrency channels
by codesnips 3 tabs
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