22 articles
Knowledge Base
Go
22 articles in the Go category.
- Embedding static assets in Go binaries with embed.FS Ship your Go web app as one binary by using the embed package built into Go to compile its templates, SQL migrations and static files into the executable. You will also serve those files with long-lived cache headers and keep a development mode that reads them straight from disk.
- HTTP services in Go with Echo — routing, middleware, and templating Build a production Go HTTP service with the Echo framework — context wrapper, validator integration, middleware chains, graceful shutdown, and Prometheus metrics.
- HTTP routing in Go services with chi Use chi to build a Go HTTP server with middleware chains, nested subrouters, URL params, and graceful shutdown. The recommended router pattern for new services.
- Structured logging in Go with the slog standard library Use Go 1.21+ log/slog for JSON structured logs, contextual attributes, dynamic levels, and OpenTelemetry trace correlation. Replaces logrus and zap for new services.
- Go modules in depth: vendoring, workspaces, and reproducible builds Operate Go modules in production — go.mod hygiene, vendoring choices, GOFLAGS for CI, workspaces for multi-module repos, and the proxy/sumdb story.
- Building a production gRPC service in Go Define a .proto, generate Go stubs, run a gRPC server with TLS, add interceptors for auth/logging/metrics, and ship a Go client. Includes graceful shutdown.
- Installing Go and running Go binaries under systemd Install Go from the official tarball, build a static binary, and supervise it as a sandboxed systemd service.
- Hunting goroutine leaks in a long-running Go service Spot a goroutine leak from pprof and metrics, find the leaking stack, and fix the four classic causes — unclosed channels, missing context cancel, leaked HTTP responses, ticker leaks.
- Configuration management in Go services with Viper Load Go service configuration from files, environment variables, and CLI flags with Viper. Cover precedence, watch-on-reload, and how to keep secrets out of YAML.
- Instrumenting Go services with the OpenTelemetry SDK Wire OpenTelemetry tracing, metrics, and logs into a Go service — OTLP exporter, resource attributes, propagation, and how to keep span cardinality under control.
- Connecting Go services to NATS and JetStream Connect a Go service to NATS with reconnect handling, JetStream pull consumers, durable subscriptions, ack/nak semantics, and graceful shutdown.
- Catching data races in Go with -race in tests and CI Use go test -race to detect data races in concurrent Go code, interpret the report, fix the four common race patterns, and wire -race into CI without paying for it in prod builds.
- Building production CLIs in Go with Cobra Use Cobra to scaffold a multi-command Go CLI with flags, subcommands, shell completion, and config-file loading via Viper. Covers exit codes, logging, and testing.
- Releasing Go binaries with GoReleaser — multi-arch, signed, and SBOM-aware Set up GoReleaser to build Go binaries for multiple OS/arch, sign them with cosign, generate an SBOM, and publish to GitHub Releases plus Docker registries.
- Debugging Go services with Delve — local, remote, and containerized Install Delve, attach to a running Go process, debug remotely over TCP, and integrate dlv with VSCode and Goland. Covers production-safe defaults.
- Migrating off gorilla/mux to net/http or chi gorilla/mux was archived in 2022 and revived in 2023. Decide whether to stay, move to stdlib net/http (Go 1.22+), or migrate to chi — with a checklist for each path.
- The Go execution tracer — scheduling, GC, and goroutine timelines Capture a runtime/trace file from a running Go service, open it with go tool trace, and read what the scheduler and GC are doing on the timeline.
- Live-reload Go services in development with Air Configure Air to watch Go source, rebuild on save, and restart the service so feedback loops feel instant. Includes Docker, Compose, and multi-binary repos.
- Compile-time dependency injection in Go with Wire Use Google Wire to assemble a dependency graph at compile time — provider sets, injectors, error wiring, and how it compares to runtime DI containers.
- Profiling Go services in production with pprof Expose net/http/pprof safely, capture CPU and heap profiles from running services, and read flame graphs to find the hot path before it costs you SLO.
- Cross-compiling Go binaries for Linux, macOS, ARM64 Use GOOS, GOARCH, and CGO_ENABLED to produce reproducible Go binaries for every target you ship to — from amd64 Linux to ARM64 Graviton.
- Adopting Go generics in production code — when, where, and how Decide where generics actually help in Go services — slice/map utilities, type-safe stores, constraint sets — and where they make code worse than the interface alternative.