The style and environment guide for every hoardCTI repository written in Go.
hoardCTI publishes cyber threat intelligence that other organisations use to defend themselves. This guide sets out how we write, test, document and ship Go code so that code stays clear to readers who may not know Go, correct under hostile input, and consistent across every repository.
It covers the whole of Go: the toolchain and repository setup, then every language feature and standard library area we use, then testing, security and performance. Every rule has a stable ID, a MUST / SHOULD / MAY level, its reasoning, and good and bad examples.
Start here: read Principles and the House rules, then keep the Review checklist open while you work.
Six hoardCTI rules shape everything else. Some deliberately differ from common Go practice.
| Rule | In one line | |
|---|---|---|
| R1 | Yoda conditions | nil != err, "" == name, want != got |
| R2 | camelCase | MixedCaps identifiers, Go initialisms, SCREAMING_SNAKE constants |
| R3 | Minimal and modular | Code only gets its own file or package when two or more callers share it |
| R4 | 100% test coverage | Every package and the total, enforced in CI |
| R5 | Descriptive names | Full words, except a short fixed allowlist |
| R6 | Comment everything | Every declaration documented, and Go explained for non-Go readers |
- Principles: audience, how to read a rule, rule
IDs, precedence, core principles (
GO-GEN) - House rules: the six hoardCTI rules at a glance
- Toolchain: Go version policy,
goandtoolchainlines, installing Go (GO-ENV) - Modules and dependencies: module
path, multiple modules,
go.work,replace, tool directives, dependency policy, Dependabot (GO-MOD) - Editor setup: gopls, VS Code, GoLand, Neovim,
.editorconfig(GO-EDT) - Makefile: standard targets and
make check(GO-MAK) - Continuous integration: the Go CI
job, hardening, caching, coverage summary (
GO-CI) - Configuration: flags, environment,
.env, secrets, precedence (GO-CFG) - Building: static builds,
-trimpath, versions, targets (GO-BLD)
- Repository layout:
cmd/,internal/,testdata/(GO-LAY) - Packages and files: house rule R3,
and file order (
GO-PKG) - Main packages:
main→run, wiring, signals (GO-MAIN) - Build tags, generate and embed:
//go:build,//go:generate,//go:embed(GO-BTG)
- Formatting: gofumpt, line length, literals,
octal, magic numbers (
GO-FMT) - Imports: grouping, aliases, blank and dot imports
(
GO-IMP)
- Identifiers: house rules R2 and R5: casing,
initialisms, SCREAMING constants, the short-name allowlist, receivers,
shadowing, packages, files (
GO-NAM) - External names: JSON, environment variables,
flags, log keys (
GO-EXT)
- Comments: house rule R6: what must be
commented, how, and what never to write (
GO-DOC) - Explaining Go: the catalogue of Go
mechanisms to explain for non-Go readers (
GO-EXP)
- Control flow: house rule R1 (Yoda), early
returns, no nesting,
switch, loops, labels (GO-CTL) - Declarations:
:=versusvar, scope, enums,init, globals,new(value), aliases (GO-DEC) - Data types: slices, maps, strings, structs,
pointers, numbers (
GO-TYP) - Functions and methods: signatures,
results, receivers, closures, size limits (
GO-FUN) - Interfaces: consumer-defined, small, type
assertions, nil pitfalls (
GO-IFC) - Generics and iterators: when to use
them, generic methods,
iter.Seq(GO-GNR) - defer, panic and recover (
GO-DPR) - Restricted features:
unsafe,reflect, cgo, linkname, plus every ban in one table (GO-RST) - Modern Go:
go fixmodernisers and the table of modern replacements (GO-MDN)
- Errors: returning, messages, wrapping, sentinels and
types, handling once, batches, secrets (
GO-ERR)
- Goroutines: lifetimes,
WaitGroup.Go,errgroup, bounded concurrency (GO-GOR) - Channels: direction, buffering, closing,
cancellation (
GO-CHN) - sync and atomics: mutex placement,
copying, atomics,
OnceValue(GO-SYN) - context: passing, storing, values, cancellation
(
GO-CTX) - Patterns: worker pools, rate limiting, retry
with backoff, pipelines (
GO-PAT)
- Logging:
log/slog, handlers, messages, keys, secrets (GO-LOG) - HTTP: clients (timeouts, bodies, limits, URLs)
and servers (routing, timeouts, shutdown) (
GO-HTP) - JSON:
encoding/json/v2, tags,omitzero, typed decoding, deterministic output (GO-JSN) - Time: types, UTC, injected clocks, layouts
(
GO-TIM) - Files and paths:
filepath,os.Root, atomic writes, permissions (GO-FIL) - Command line: flags, exit codes,
stdout and stderr, validation (
GO-CLI) - Other packages:
strconv,netip,uuid,regexp, randomness,os/exec, CSV (GO-LIB)
- Coverage: house rule R4: 100%, measurement,
enforcement, exceptions (
GO-COV) - Writing tests: files, names, tables, messages,
cmp, parallelism, testingrun(GO-TST) - Test doubles and fixtures:
httptest, fakes, mocks,testdata/, golden files (GO-TDF) - Specialised tests: fuzzing, benchmarks,
synctest, race detector, live tests, flaky tests (GO-SPT)
- Security: threat model, untrusted input, size
limits, secrets, TLS,
gosec,govulncheck, SSRF (GO-SEC)
- API design: functional options, validation,
Close, no hidden goroutines, configuration flow (GO-API)
- Performance: measure first,
pprof, allocation, streaming (GO-PRF)
- Review checklist: every MUST and MUST NOT rule on one page
- Rule index: every rule ID with its title and level
- Glossary: Go terms for readers new to Go
- AI assistants: keeping AI-written code on style
- Ready-to-copy configuration:
.golangci.yml, Yoda ruleguard rules,.testcoverage.yml,Makefile, editor settings, Dependabot,AGENTS.md, CI job
If you are an AI coding agent, start with the agent skill:
https://style.hoardcti.com/v1/golang/SKILL.md.
It explains how to read the guide, find a rule by its
ID, and apply the guide when writing or reviewing Go code. Save it to your
skills directory to install it.
- Every page on the site is also served as raw Markdown: swap
.htmlfor.mdin the URL, for examplehttps://style.hoardcti.com/v1/golang/errors/errors.md. llms.txtlists every page as raw Markdown, with the skill first.- Repositories that follow the guide commit
AGENTS.mdat their root. See AI assistants.
When this guide is silent, follow the Google Go Style Guide, then Go Code Review Comments, then Effective Go (GO-GEN-001).
Changes are made by pull request with one approval from a Go code owner. See CONTRIBUTING.md and CHANGELOG.md.