Skip to content

About

The style and environment guide for every hoardCTI repository written in Go.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

hoardCTI Go Style Guide

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.

The house rules

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

Contents

Foundations

  • Principles: audience, how to read a rule, rule IDs, precedence, core principles (GO-GEN)
  • House rules: the six hoardCTI rules at a glance

1. Environment

  • Toolchain: Go version policy, go and toolchain lines, 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)

2. Structure

3. Formatting

  • Formatting: gofumpt, line length, literals, octal, magic numbers (GO-FMT)
  • Imports: grouping, aliases, blank and dot imports (GO-IMP)

4. Naming

  • 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)

5. Documentation

  • 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)

6. Language

7. Errors

  • Errors: returning, messages, wrapping, sentinels and types, handling once, batches, secrets (GO-ERR)

8. Concurrency

  • 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)

9. Standard library

  • 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)

10. Testing

  • Coverage: house rule R4: 100%, measurement, enforcement, exceptions (GO-COV)
  • Writing tests: files, names, tables, messages, cmp, parallelism, testing run (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)

11. Security

  • Security: threat model, untrusted input, size limits, secrets, TLS, gosec, govulncheck, SSRF (GO-SEC)

12. API design

  • API design: functional options, validation, Close, no hidden goroutines, configuration flow (GO-API)

13. Performance

  • Performance: measure first, pprof, allocation, streaming (GO-PRF)

Appendices

For AI agents

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 .html for .md in the URL, for example https://style.hoardcti.com/v1/golang/errors/errors.md.
  • llms.txt lists every page as raw Markdown, with the skill first.
  • Repositories that follow the guide commit AGENTS.md at their root. See AI assistants.

Precedence

When this guide is silent, follow the Google Go Style Guide, then Go Code Review Comments, then Effective Go (GO-GEN-001).

Contributing

Changes are made by pull request with one approval from a Go code owner. See CONTRIBUTING.md and CHANGELOG.md.

About

The style and environment guide for every hoardCTI repository written in Go.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages