Go#
Go is the default for shippable, long-running service code and self-contained CLIs. Statically typed, garbage-collected, compiled to a single static binary, opinionated about formatting, with a tight standard library and first-class concurrency through goroutines and channels.
For the operator, Go is the language for tools that need to
live on a target without a runtime: agents, beacons, implants,
scanners, proxies, anything where you want a single
GOOS=linux GOARCH=amd64 go build to produce a binary they
can drop and run.
Baseline. Go 1.22+ is assumed. Generics (func F[T any]),
for range over int, structured logging (log/slog), and
the errors.Join family are written without apology.
Default toolchain. go for build / test / format / lint
(go vet, gofmt); golangci-lint for the wider linter
catalogue; govulncheck for CVE scanning; dlv for
debugging.
Setup#
Picking the right Go and getting the toolchain on the host.
go, gvm, goenv, brew, apt,
GOROOT, GOPATH. Picking a version and
bootstrapping a module.
go, gofmt, go vet, golangci-lint,
govulncheck, dlv, goreleaser. The toolchain
around the compiler.
Single-expression Go idioms: os.ReadFile,
strings.Join, strconv, defer, net.Dial.
Language#
The spec building blocks.
//, /* */, ;, true false nil iota.
Comments, identifiers, keywords, literals, statements
vs expressions.
var, :=, const, blank _. Declaration,
short assignment, zero values, scope.
int float bool string byte rune, structs, slices,
maps, pointers, interfaces, type assertions, any.
+ - * / %, == != < >, && || !,
& | ^ << >> &^, & *, <-. Arithmetic,
logical, bitwise, pointer, channel.
if, for, switch, select,
break continue return goto fallthrough,
defer. Branching, loops, jumps, deferred calls.
func, multiple returns, named returns, variadic,
closures, defer, generics ([T any]), method
receivers.
struct, methods, embedding, interface,
satisfaction, type assertions, type switches. No
inheritance.
Patterns#
The layer above the spec.
Errors as values, accept interfaces / return structs,
context first, table-driven tests, functional
options, small interfaces.
error, errors.Is, errors.As,
errors.Join, fmt.Errorf %w, sentinel errors,
typed errors, panic / recover.
Data Structures#
The container catalog.
Arrays, slices, maps, sync.Map,
container/list, container/heap,
container/ring. Built-in and stdlib containers.
sort, slices, maps, cmp, hash,
crypto. The generic algorithm catalogue.
I/O#
Talking to files, the network, the shell, and the OS.
io, os, bufio, encoding/json,
encoding/binary, fmt. Files, streams,
formatting, parsing.
os.Args, flag, cobra, urfave/cli,
os.Exit, exit codes, stdin / stdout streaming.
net, net/http, crypto/tls, net/url,
golang.org/x/crypto/ssh. TCP, UDP, HTTP, TLS, SSH.
go, channels, select, sync.WaitGroup,
sync.Mutex, context, errgroup. The
goroutine model.
Runtime#
The compiler, the module system, and what happens between source and the binary.
go build, go mod, GOOS, GOARCH,
go.sum, vendoring, the scheduler, GC, escape
analysis.
Ecosystem#
The standard library and the third-party catalog.
Stdlib: net/http, encoding/*, sync,
context. Modules: cobra, viper,
logrus / zap, sqlx, go-redis,
testify.
Web: chi, echo, gin, fiber.
RPC: gRPC-go, connect-go. CLI:
cobra, urfave/cli. Build: goreleaser.
Practice#
The disciplines that make a binary safe to ship.
testing, table-driven tests, t.Run,
testify, go test -race, fuzz tests, benchmarks.
End-to-end Go projects, a scanner, a beacon, a
cobra-driven CLI, a small HTTP service.