skip to content
Sandip's Blog
Table of Contents

Standard library you must know

Area Packages
I/O io, bufio, os, io/fs, embed
Text strings, bytes, strconv, unicode, regexp, text/template, html/template
Data formats encoding/json, encoding/xml, encoding/csv, encoding/gob, encoding/base64
Time time (durations, formatting layout 2006-01-02, timezones, monotonic clock)
Networking net, net/http, net/url, net/http/httptest
Logging log, log/slog (structured logging, preferred)
Collections slices, maps, container/heap, container/list
Math math, math/rand/v2, math/big
Crypto crypto/sha256, crypto/rand, crypto/tls, crypto/hmac
System os/exec, os/signal, flag, path/filepath
Database database/sql
Misc sort, errors, fmt, testing, context, sync, runtime

Deep dives

  • io.Reader/io.Writer composition: io.Copy, io.TeeReader, io.MultiWriter, io.Pipe
  • bufio.Scanner (and its token size limit) vs bufio.Reader
  • encoding/json: tags, omitempty, json.RawMessage, custom MarshalJSON, streaming with Decoder/Encoder
  • net/http: Client (timeouts!), Server, Handler, ServeMux (method and wildcard routing in 1.22+), middleware
  • time: never use time.Sleep for sync; use Timer/Ticker and stop them
  • log/slog: handlers, levels, attributes, groups
  • flag and building CLIs (also look at cobra)
  • embed for static files

Tooling

Core commands

go run / build / install
go fmt ./... # or gofmt -s
go vet ./...
go test ./... -race -cover
go mod tidy
go doc <pkg>
go generate
go env
go list -m all
go work

Must-use tools

  • gopls: language server (VS Code Go extension / GoLand)
  • golangci-lint: lint aggregator
  • staticcheck
  • govulncheck: security vulnerabilities
  • delve (dlv): debugger
  • goimports
  • air (live reload), mockgen / mockery (mocks)
  • sqlc, goose / migrate (DB)

Build and release

  • Cross-compilation: GOOS=linux GOARCH=amd64 go build
  • Build tags / constraints
  • -ldflags "-s -w -X main.version=..."
  • Static binaries with CGO_ENABLED=0
  • Multi-stage Docker builds (final image scratch or distroless)
  • GoReleaser

Visual: a typical CI pipeline

flowchart LR
  A["git push"] --> B["gofmt / goimports"]
  B --> C["go vet"]
  C --> D["golangci-lint"]
  D --> E["go test -race -cover"]
  E --> F["govulncheck"]
  F --> G["go build (CGO_ENABLED=0)"]
  G --> H["Docker image"]

Practice

  • Build a CLI tool (e.g. grep clone) using only the stdlib
  • Write a JSON log analyzer using bufio + encoding/json
  • Add golangci-lint + govulncheck to a project’s CI

Previous: Go Mastery 3: Concurrency Done Right
Next: Go Mastery 5: Testing, Profiling and Internals

Back to the roadmap