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.

Setup

go, gvm, goenv, brew, apt, GOROOT, GOPATH. Picking a version and bootstrapping a module.

Setup
Tooling

go, gofmt, go vet, golangci-lint, govulncheck, dlv, goreleaser. The toolchain around the compiler.

Tooling
Snippets

Single-expression Go idioms: os.ReadFile, strings.Join, strconv, defer, net.Dial.

Snippets

Language#

The spec building blocks.

Syntax

//, /* */, ;, true false nil iota. Comments, identifiers, keywords, literals, statements vs expressions.

Syntax
Variables

var, :=, const, blank _. Declaration, short assignment, zero values, scope.

Variables
Types

int float bool string byte rune, structs, slices, maps, pointers, interfaces, type assertions, any.

Types
Operators

+ - * / %, == != < >, && || !, & | ^ << >> &^, & *, <-. Arithmetic, logical, bitwise, pointer, channel.

Operators
Controls

if, for, switch, select, break continue return goto fallthrough, defer. Branching, loops, jumps, deferred calls.

Control flow
Functions

func, multiple returns, named returns, variadic, closures, defer, generics ([T any]), method receivers.

Functions
OOP

struct, methods, embedding, interface, satisfaction, type assertions, type switches. No inheritance.

OOP

Patterns#

The layer above the spec.

Patterns

Errors as values, accept interfaces / return structs, context first, table-driven tests, functional options, small interfaces.

Patterns
Errors

error, errors.Is, errors.As, errors.Join, fmt.Errorf %w, sentinel errors, typed errors, panic / recover.

Errors

Data Structures#

The container catalog.

Structures

Arrays, slices, maps, sync.Map, container/list, container/heap, container/ring. Built-in and stdlib containers.

Data Structures
Algorithms

sort, slices, maps, cmp, hash, crypto. The generic algorithm catalogue.

Algorithms

I/O#

Talking to files, the network, the shell, and the OS.

I/O

io, os, bufio, encoding/json, encoding/binary, fmt. Files, streams, formatting, parsing.

I/O
CLI

os.Args, flag, cobra, urfave/cli, os.Exit, exit codes, stdin / stdout streaming.

CLI
Networking

net, net/http, crypto/tls, net/url, golang.org/x/crypto/ssh. TCP, UDP, HTTP, TLS, SSH.

Networking
Concurrency

go, channels, select, sync.WaitGroup, sync.Mutex, context, errgroup. The goroutine model.

Concurrency

Runtime#

The compiler, the module system, and what happens between source and the binary.

Runtime

go build, go mod, GOOS, GOARCH, go.sum, vendoring, the scheduler, GC, escape analysis.

Runtime

Ecosystem#

The standard library and the third-party catalog.

Libraries

Stdlib: net/http, encoding/*, sync, context. Modules: cobra, viper, logrus / zap, sqlx, go-redis, testify.

Libraries
Frameworks

Web: chi, echo, gin, fiber. RPC: gRPC-go, connect-go. CLI: cobra, urfave/cli. Build: goreleaser.

Frameworks

Practice#

The disciplines that make a binary safe to ship.

Testing

testing, table-driven tests, t.Run, testify, go test -race, fuzz tests, benchmarks.

Testing
Projects

End-to-end Go projects, a scanner, a beacon, a cobra-driven CLI, a small HTTP service.

Projects