@srobroek/pi-lang-go 0.0.0-stage → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ # Go command-line applications
2
+
3
+ Keep small tools on the standard library and reserve rich terminal dependencies for interactive needs.
4
+
5
+ Checked 2026-11-12. Standard-library entries use Go `1.27`.
6
+
7
+ | Concern | Default | Use instead when | Avoid (why) |
8
+ | --- | --- | --- | --- |
9
+ | Small CLI | `flag`, `fmt`, `os`; standard library is sufficient | `github.com/spf13/cobra` `>= 1` for command trees/completions | Command framework for a few flags. |
10
+ | Structured commands | Cobra `1` for established command-tree conventions | `github.com/alecthomas/kong` `>= 1` for struct parsing; `github.com/urfave/cli/v3` `>= 3` for its API | Treating `github.com/peterbourgon/ff/v4` `>= 4` beta as stable. |
11
+ | Prompts/forms | Noninteractive flags first | `charm.land/huh/v2` `>= 2` for forms | Blocking prompts in automation; old Charm paths mistaken for v2 modules. |
12
+ | Full TUI | `charm.land/bubbletea/v2` `>= 2` when a stateful TUI is needed | `charm.land/bubbles/v2` `>= 2` for components | A TUI for ordinary command output; blocking work in the event/update path. |
13
+ | Plain/machine output | `fmt`, `encoding/json`, `text/tabwriter`; standard library is sufficient | `github.com/fatih/color` `>= 1` for modest color; `charm.land/lipgloss/v2` `>= 2` for styling | ANSI on machine output, diagnostics mixed with JSON stdout. |
14
+ | Tiny configuration | `os.LookupEnv`, typed immutable structs; standard library is sufficient | `github.com/caarlos0/env/v11` `>= 11` for typed environment parsing | Hidden defaults, no startup validation or mutable global settings. |
15
+ | Layered configuration | `github.com/knadh/koanf/v2` `>= 2` when files/env/flags must combine | `github.com/spf13/viper` `>= 1` for existing Cobra integrations; `github.com/kelseyhightower/envconfig` `>= 1` for existing code | Viper concurrent reads/writes, case-sensitive-key assumptions or unnoticed environment rereads. |
16
+ | Config formats | JSON via standard library when sufficient | Maintained YAML `3` or TOML `2` modules from `data.md` | Inventing parsers or installing formats the project does not need. |
17
+
18
+ ## Rules
19
+
20
+ - Define and test config precedence; parse once, validate and freeze typed settings. Keep secrets out of printed diagnostics.
21
+ - Support noninteractive execution, cancellation, sensible exit status and plain/machine output. Keep diagnostics on stderr.
22
+ - Respect terminal capability and non-TTY output. Test command behavior separately from the terminal renderer.
23
+ - Flush telemetry on command exit; do not replace explicit startup/shutdown with a middleware framework for one command.
24
+
25
+ ## Sources
26
+
27
+ - [flag](https://pkg.go.dev/flag), [Cobra](https://pkg.go.dev/github.com/spf13/cobra), [Kong](https://pkg.go.dev/github.com/alecthomas/kong), [urfave CLI](https://pkg.go.dev/github.com/urfave/cli/v3), [ff beta](https://pkg.go.dev/github.com/peterbourgon/ff/v4).
28
+ - [Bubble Tea](https://pkg.go.dev/charm.land/bubbletea/v2), [Bubbles](https://pkg.go.dev/charm.land/bubbles/v2), [Huh](https://pkg.go.dev/charm.land/huh/v2), [Lip Gloss](https://pkg.go.dev/charm.land/lipgloss/v2), [color](https://pkg.go.dev/github.com/fatih/color), [tabwriter](https://pkg.go.dev/text/tabwriter).
29
+ - [env](https://pkg.go.dev/github.com/caarlos0/env/v11), [koanf](https://pkg.go.dev/github.com/knadh/koanf/v2), [Viper behavior](https://github.com/spf13/viper#readme), [envconfig](https://pkg.go.dev/github.com/kelseyhightower/envconfig).
@@ -0,0 +1,46 @@
1
+ # Go data and persistence
2
+
3
+ Choose codecs and clients for the actual format, database and workload rather than a uniform abstraction.
4
+
5
+ Checked 2026-11-12. Standard-library entries use Go `1.27`.
6
+
7
+ | Concern | Default | Use instead when | Avoid (why) |
8
+ | --- | --- | --- | --- |
9
+ | Small boundary validation | Explicit checks; standard library is sufficient | `github.com/go-playground/validator/v10` `>= 10` for DTO tags | Tags standing in for business invariants or authorization. |
10
+ | JSON | `encoding/json` for compatible contracts; standard library is sufficient | `encoding/json/v2` for new Go `1.27` contracts; `github.com/goccy/go-json` `>= 0.12` or `github.com/bytedance/sonic` `>= 1` only after profiling/platform checks | Untested semantic migrations; v2 rejects duplicate names and invalid UTF-8 by default. |
11
+ | YAML | `go.yaml.in/yaml/v3` `>= 3` | `github.com/goccy/go-yaml` `>= 1` for parser/error tooling | New dependencies on `gopkg.in/yaml.v3`: original repository archived. |
12
+ | TOML | `github.com/pelletier/go-toml/v2` `>= 2` | `github.com/BurntSushi/toml` `>= 1` for existing conventions | Custom parsers or unsupported inactivity claims. |
13
+ | CSV | `encoding/csv`; standard library is sufficient | Domain schema mapping over the codec | Comma splitting; unchecked spreadsheet formula injection on export. |
14
+ | MessagePack | JSON unless binary protocol is required | `github.com/vmihailenco/msgpack/v5` `>= 5` for MessagePack contracts | Binary encoding without interoperability or size requirements. |
15
+ | Protobuf | `google.golang.org/protobuf` `>= 1` for Protobuf contracts | JSON for ordinary human-facing interfaces | Hand-marshaling generated messages. |
16
+ | Avro | JSON/Protobuf unless an Avro contract exists | `github.com/hamba/avro/v2` `>= 2` for Avro encoding; registry integration verified separately | Assuming a codec supplies schema-registry discovery and evolution policy. |
17
+ | Parquet | `github.com/parquet-go/parquet-go` `>= 0.32` for Parquet files | `github.com/apache/arrow-go/v18` `>= 18` for Arrow arrays/IPC | Treating columnar files and in-memory Arrow as interchangeable. |
18
+ | PostgreSQL | `github.com/jackc/pgx/v5` `>= 5` plus `github.com/sqlc-dev/sqlc` `>= 1` | `database/sql` for portable database APIs; standard library suffices for pooling over a selected driver | Connection-per-query, string-built SQL or redundant pools. |
19
+ | Query builders and ORMs | SQL and generated queries first | `gorm.io/gorm` `>= 1` for runtime ORM; `entgo.io/ent` `>= 0` for generated entities; `github.com/uptrace/bun` `>= 1` for SQL-oriented ORM | ORM adoption without needed capabilities; hidden N+1 and transaction semantics. |
20
+ | Struct scanning | Driver scanning or generated SQL | `github.com/jmoiron/sqlx` `>= 1` for existing struct-scanning code | Calling sqlx archived: it is not; old release/activity requires responsiveness checks. |
21
+ | Migrations | `github.com/pressly/goose/v3` `>= 3` | `github.com/golang-migrate/migrate/v4` `>= 4` for its drivers; `ariga.io/atlas` `>= 1` for declarative planning | Production ORM auto-migration; ignoring Atlas edition/license boundaries. |
22
+ | Pooling | `github.com/jackc/pgx/v5/pgxpool` `>= 5` or `database/sql` | Direct connections for explicitly constrained lifecycle/concurrency | Unbounded pool counts across replicas; pool over another pool. |
23
+ | Valkey/Redis | `github.com/valkey-io/valkey-go` `>= 1`; `github.com/redis/go-redis/v9` `>= 9` for Redis | `github.com/redis/rueidis` `>= 1` for its API/cache model; GLIDE `2` for cross-language AWS behavior, detailed in `aws.md` | Claims that only rueidis has automatic pipelining/client caching; current go-redis has both. |
24
+ | In-process cache | Map plus mutex or `sync.Map`; standard library suffices without eviction | `github.com/maypok86/otter/v2` `>= 2` for eviction; `github.com/dgraph-io/ristretto/v2` `>= 2` for cost-based admission | Approximate cache as authoritative state; Ristretto can drop sets. |
25
+ | Search | SQL search until inadequate | `github.com/opensearch-project/opensearch-go/v4` `>= 4`, `github.com/elastic/go-elasticsearch/v9` `>= 9` or `/v8` `>= 8` matched to product/server | Assuming Elasticsearch and OpenSearch clients are interchangeable. |
26
+ | Other search | Selected server's official client | `github.com/meilisearch/meilisearch-go` `>= 0.37`; `github.com/blevesearch/bleve/v2` `>= 2` for embedded indexing | Adding a search server before demonstrating the SQL gap. |
27
+ | Vectors | `github.com/pgvector/pgvector-go` `>= 0.4` with PostgreSQL pgvector | Dedicated vector service for measured scale/features | Confusing the Go adapter with the database extension. |
28
+ | Object storage | AWS SDK v2 S3 client for simple objects | `github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager` `>= 0.5` for multipart/transfers; `gocloud.dev/blob` `>= 0.48` for genuine provider portability | New use of deprecated S3 manager uploader/downloader APIs. |
29
+ | Embedded analytics | Database SQL for ordinary service queries | `github.com/duckdb/duckdb-go/v2` `>= 2` for embedded analytics | Assuming DuckDB is pure-Go or simple static cross-compilation; plan CGO. |
30
+ | Numerical processing | `math`; standard library suffices for elementary operations | `gonum.org/v1/gonum` `>= 0.17` for numerical algorithms | Inferring module major `1` from Gonum's hostname path; unvalidated custom algorithms. |
31
+
32
+ ## Rules
33
+
34
+ - Bound decode size, depth, record count and decompression. Validate external data before domain construction.
35
+ - Keep transactions and conditional writes explicit. Test concurrency, rollback, pagination and pool exhaustion against real infrastructure.
36
+ - Pin pre-stable modules and review wire/schema changes on upgrades. Preserve a raw-driver/SDK escape hatch.
37
+ - Choose cache TTL and invalidation against acceptable staleness, not only benchmark throughput.
38
+
39
+ ## Sources
40
+
41
+ - [JSON changes](https://go.dev/doc/go1.27), [validator](https://pkg.go.dev/github.com/go-playground/validator/v10), [YAML](https://pkg.go.dev/go.yaml.in/yaml/v3), [original YAML archive](https://github.com/go-yaml/yaml), [TOML](https://pkg.go.dev/github.com/pelletier/go-toml/v2), [CSV](https://pkg.go.dev/encoding/csv).
42
+ - [MessagePack](https://pkg.go.dev/github.com/vmihailenco/msgpack/v5), [Protobuf](https://pkg.go.dev/google.golang.org/protobuf), [Avro](https://pkg.go.dev/github.com/hamba/avro/v2), [Parquet](https://pkg.go.dev/github.com/parquet-go/parquet-go), [Arrow](https://pkg.go.dev/github.com/apache/arrow-go/v18).
43
+ - [pgx](https://pkg.go.dev/github.com/jackc/pgx/v5), [sqlc](https://pkg.go.dev/github.com/sqlc-dev/sqlc), [standard SQL](https://pkg.go.dev/database/sql), [GORM](https://pkg.go.dev/gorm.io/gorm), [ent](https://pkg.go.dev/entgo.io/ent), [Bun](https://pkg.go.dev/github.com/uptrace/bun), [Goose](https://pkg.go.dev/github.com/pressly/goose/v3), [migrate](https://pkg.go.dev/github.com/golang-migrate/migrate/v4), [Atlas](https://atlasgo.io/).
44
+ - [Valkey](https://pkg.go.dev/github.com/valkey-io/valkey-go), [go-redis](https://pkg.go.dev/github.com/redis/go-redis/v9), [rueidis](https://pkg.go.dev/github.com/redis/rueidis), [Otter](https://pkg.go.dev/github.com/maypok86/otter/v2), [Ristretto](https://pkg.go.dev/github.com/dgraph-io/ristretto/v2).
45
+ - [OpenSearch](https://pkg.go.dev/github.com/opensearch-project/opensearch-go/v4), [Elasticsearch](https://pkg.go.dev/github.com/elastic/go-elasticsearch/v9), [Meilisearch](https://pkg.go.dev/github.com/meilisearch/meilisearch-go), [Bleve](https://pkg.go.dev/github.com/blevesearch/bleve/v2), [pgvector](https://pkg.go.dev/github.com/pgvector/pgvector-go).
46
+ - [S3 transfer manager](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager), [Go Cloud](https://pkg.go.dev/gocloud.dev/blob), [DuckDB build](https://github.com/duckdb/duckdb-go#cross-compilation), [Gonum](https://pkg.go.dev/gonum.org/v1/gonum).
@@ -0,0 +1,35 @@
1
+ # Go jobs and messaging
2
+
3
+ Use broker-native clients and reviewed delivery policies for durable work, not detached goroutines.
4
+
5
+ Checked 2026-11-12. Standard-library entries use Go `1.27`.
6
+
7
+ | Concern | Default | Use instead when | Avoid (why) |
8
+ | --- | --- | --- | --- |
9
+ | In-process work | `context`, channels and bounded goroutines; standard library is sufficient for non-durable work | A durable queue when accepted work must survive termination | Returning success before non-durable work completes when durability is promised. |
10
+ | PostgreSQL jobs | `github.com/riverqueue/river` `>= 0.51` for applications already using PostgreSQL | `github.com/hibiken/asynq` `>= 0.26` for Redis task queues | Detached goroutines for durable jobs; nontransactional enqueue after a required database write. |
11
+ | Durable workflows | `go.temporal.io/sdk` `>= 1` for multi-step durable orchestration | `github.com/aws/aws-durable-execution-sdk-go` `>= 1` for Lambda replay/checkpoints; AWS Step Functions for cross-service orchestration | Ordinary nondeterministic work or uncontrolled effects during replay. |
12
+ | Simple periodic work | `time.Ticker`; standard library is sufficient | `github.com/robfig/cron/v3` `>= 3` for cron expressions; `github.com/go-co-op/gocron/v2` `>= 2` for richer scheduling/coordination | Treating in-process scheduling as durable distributed execution; inferring abandonment from cron's old tag. |
13
+ | Durable schedules | Managed scheduler invoking an idempotent worker | Temporal `1` schedules when already using Temporal | Sleeping in billed Lambda handlers or a per-replica timer issuing duplicate writes. |
14
+ | Kafka | `github.com/twmb/franz-go` `>= 1` | `github.com/IBM/sarama` `>= 1` for existing systems; `github.com/confluentinc/confluent-kafka-go/v2` `>= 2` for librdkafka requirements | Old Shopify Sarama imports; native deployment burden without need. |
15
+ | RabbitMQ | `github.com/rabbitmq/amqp091-go` `>= 1` | Broker-specific protocols for explicit requirements | Assuming automatic reconnection or topology restoration. |
16
+ | NATS | `github.com/nats-io/nats.go` `>= 1` with its `jetstream` API for durable consumers | Core NATS for transient pub/sub | New durable consumers on legacy JetStream interfaces. |
17
+ | Pipeline abstraction | Direct broker client first | `github.com/ThreeDotsLabs/watermill` `>= 1` for reusable pipelines/adapters | Hiding ordering, acknowledgment and retry semantics behind generic interfaces. |
18
+ | AWS publishing | AWS SDK v2 service clients for SQS, SNS and EventBridge | Existing framework queue adapter when lifecycle is already managed | Adding a task framework for simple SNS/EventBridge publishing. |
19
+ | SQS worker | SDK polling with cancellation, visibility renewal, deletion and backoff | Lambda event-source mapping for managed polling and scaling | A polling library inside event-source-mapped Lambda; no independently verified Go worker wrapper is recommended. |
20
+ | CloudEvents | Application-owned envelope when interoperability is unnecessary | `github.com/cloudevents/sdk-go/v2` `>= 2` for CloudEvents contracts | An envelope standard presented as exactly-once delivery. |
21
+ | Idempotency | Database unique keys/transactions or DynamoDB conditional writes | Downstream idempotency token where supported | Check-then-write deduplication, invocation IDs as business keys, or a cache as the durable ledger. |
22
+
23
+ ## Rules
24
+
25
+ - Scope deduplication to principal and operation, with payload mismatch and expiry rules. Model in-progress/completed outcomes; TTL is cleanup, not proof of exclusive ownership.
26
+ - Acknowledge after the durable effect succeeds. Test poison records, redelivery, visibility expiry, shutdown and FIFO ordering.
27
+ - Extract message trace context; inject it when publishing. Use an outbox when database writes and event publication must agree.
28
+ - Configure bounded retries, jitter and dead-letter handling. Middleware wraps processors; domain decisions remain in testable business functions.
29
+
30
+ ## Sources
31
+
32
+ - [River](https://pkg.go.dev/github.com/riverqueue/river), [Asynq](https://pkg.go.dev/github.com/hibiken/asynq), [Temporal](https://pkg.go.dev/go.temporal.io/sdk), [Lambda durable SDK](https://github.com/aws/aws-durable-execution-sdk-go/releases/tag/v1.0.0).
33
+ - [cron](https://pkg.go.dev/github.com/robfig/cron/v3), [gocron](https://pkg.go.dev/github.com/go-co-op/gocron/v2), [franz-go](https://pkg.go.dev/github.com/twmb/franz-go), [Sarama](https://pkg.go.dev/github.com/IBM/sarama), [Confluent](https://pkg.go.dev/github.com/confluentinc/confluent-kafka-go/v2).
34
+ - [RabbitMQ](https://pkg.go.dev/github.com/rabbitmq/amqp091-go), [NATS JetStream](https://github.com/nats-io/nats.go/blob/main/jetstream/README.md), [Watermill](https://pkg.go.dev/github.com/ThreeDotsLabs/watermill), [CloudEvents](https://pkg.go.dev/github.com/cloudevents/sdk-go/v2).
35
+ - [SQS](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html), [Lambda best practices](https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html), [EventBridge bindings](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-schema-code-bindings.html).
@@ -0,0 +1,40 @@
1
+ # Go observability
2
+
3
+ Use structured logging and explicit OpenTelemetry instrumentation with portable OTLP export.
4
+
5
+ Checked 2026-11-12. Standard-library entries use Go `1.27`.
6
+
7
+ | Concern | Default | Use instead when | Avoid (why) |
8
+ | --- | --- | --- | --- |
9
+ | Service logging | `log/slog` with `JSONHandler`; standard library is sufficient | `github.com/lmittmann/tint` `>= 1` for development; existing `go.uber.org/zap` `>= 1` or `github.com/rs/zerolog` `>= 1` integrations or measured needs | Replacing the logger without a concrete benefit; plaintext-only production logs and secrets. |
10
+ | Local trace correlation | Context-aware slog calls and a handler that adds active `trace_id`/`span_id` | `go.opentelemetry.io/contrib/bridges/otelslog` `>= 0.21` for exporting OTel logs | Assuming a separate `JSONHandler` gains correlation from the OTel bridge automatically. |
11
+ | SDK | `go.opentelemetry.io/otel` `>= 1`, SDK providers initialized at process entry | Existing approved OTel bootstrap package | SDK initialization per request; global providers in isolated tests. |
12
+ | OTLP export | `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp` `>= 1` and `otlpmetric/otlpmetrichttp` `>= 1` under the same exporter prefix, explicit `http/protobuf` to Collector | OTLP gRPC for deployment constraints; `go.opentelemetry.io/contrib/exporters/autoexport` `>= 0.72` for environment-selected exporters | Hard-coded vendor-only pipeline; assuming every SDK environment variable is implemented. |
13
+ | HTTP | `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` `>= 0.72` around handler and shared client transport | Existing framework instrumentation with verified equivalent coverage | Double spans; wrappers that lose flushing/hijacking support. |
14
+ | gRPC | `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` `>= 0.72` stats handlers | Connect interceptors using the matching installed API | Unverified interceptor signatures copied from a different major. |
15
+ | AWS calls | `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws` `>= 0.72` with SDK v2 | Existing approved equivalent instrumentation | Two tracing SDKs patching the same client. |
16
+ | SQL | `github.com/exaring/otelpgx` `>= 0.13` for pgx; `github.com/XSAM/otelsql` `>= 0.44` for standard SQL | Existing database instrumentation with equivalent coverage | Sensitive SQL parameters or duplicate DB spans. |
17
+ | Metrics | OTel metrics API/SDK `>= 1` in an OTel stack | `github.com/prometheus/client_golang` `>= 1` for Prometheus-native scrape services | Duplicate business metrics across APIs; unbounded labels. |
18
+ | Automatic instrumentation | Explicit source instrumentation | `go.opentelemetry.io/auto` `>= 0.24` for evaluated Linux amd64/arm64 tracing deployments | Treating a work-in-progress eBPF implementation as portable full-signal coverage. |
19
+ | Telemetry tests | `go.opentelemetry.io/otel/sdk/trace/tracetest` `>= 1`, isolated providers | SDK metric readers/log exporters for their corresponding signals | Assertions on random IDs/timestamps, real collectors in every unit test, or no flush. |
20
+
21
+ ## Signal status
22
+
23
+ The Go SDK repository and checked core `1.47` documentation call traces, metrics and logs stable. The shared language-status page still calls Go logs release candidate. Prefer the installed SDK's versioned guarantees. Re-check this discrepancy before adopting log export. Contrib bridge/instrumentation `0.x` lines have separate guarantees. Go profile support needs a separate check because the shared page leaves its status unspecified.
24
+
25
+ ## Rules
26
+
27
+ - Set `service.name`, `service.version` and `deployment.environment.name`; configure sampling and propagation explicitly. Allowlist baggage.
28
+ - Use batching in production and bounded flush/shutdown at service or CLI exit. Lambda needs invocation-end flushing, not provider shutdown per invocation; see `aws.md`.
29
+ - Use route/operation span names, bounded metric dimensions and meaningful business spans. Record errors once and set error status according to protocol semantics.
30
+ - Pin convention and instrumentation versions. Messaging, GenAI and MCP conventions remain development; stable core APIs do not stabilize every attribute.
31
+ - Structured stdout plus platform collection is sufficient when OTLP logs are not an intentional requirement. Do not ship the same logs twice.
32
+ - Test names, kinds, parentage, propagation, attributes, failure status, cardinality and absence of secrets.
33
+ - Use `quality-code-design` and `telemetry.md` for the shared telemetry checklist, and `middleware.md` for composition rules.
34
+
35
+ ## Sources
36
+
37
+ - [slog](https://pkg.go.dev/log/slog), [tint](https://pkg.go.dev/github.com/lmittmann/tint), [otelslog](https://pkg.go.dev/go.opentelemetry.io/contrib/bridges/otelslog).
38
+ - [Core status](https://github.com/open-telemetry/opentelemetry-go#project-status), [shared status](https://opentelemetry.io/docs/languages/), [core module](https://pkg.go.dev/go.opentelemetry.io/otel), [exporters](https://github.com/open-telemetry/opentelemetry-go/tree/main/exporters/otlp), [autoexport](https://pkg.go.dev/go.opentelemetry.io/contrib/exporters/autoexport).
39
+ - [Contrib instrumentation](https://github.com/open-telemetry/opentelemetry-go-contrib), [otelpgx](https://pkg.go.dev/github.com/exaring/otelpgx), [otelsql](https://pkg.go.dev/github.com/XSAM/otelsql), [automatic instrumentation status](https://github.com/open-telemetry/opentelemetry-go-instrumentation#readme).
40
+ - [Prometheus](https://pkg.go.dev/github.com/prometheus/client_golang), [trace test facilities](https://pkg.go.dev/go.opentelemetry.io/otel/sdk/trace/tracetest), [SDK environment configuration](https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/), [sensitive data](https://opentelemetry.io/docs/security/handling-sensitive-data/).
@@ -0,0 +1,66 @@
1
+ # Go quality tools
2
+
3
+ Linters, analyzers and audits for Go. Security controls and secret, SBOM, licence, container and workflow scanners are in [security.md](security.md); testing concerns are in [testing.md](testing.md).
4
+
5
+ Checked 2026-11-16.
6
+
7
+ Commands belong in `lang-go-quality`. Install policy: detect the tool, recommend the install, ask before running it (`concerns.md` in `toolchain-languages`). Prefer a `tool` directive in `go.mod` (Go 1.24+, `go get -tool`, run with `go tool <name>`); the Maintenance cell is a minimum, so use the latest release. Shared tools: `shared-tools.md` in `toolchain-languages`.
8
+
9
+ ## Concerns
10
+
11
+ | Concern | Default | Maintenance | Install | Alternatives | Use both when | Run | Avoid |
12
+ | --- | --- | --- | --- | --- | --- | --- | --- |
13
+ | `lint` | `golangci-lint` | >= 2.15.0 · 2026-10-16 · active | `golangci-lint --version` · `brew install golangci-lint` | staticcheck: standalone run without a config | `golangci-lint` bundles staticcheck, revive, errcheck and the linters below; run one binary | every-pr | Two linters with overlapping rules as separate gates; GPL-3.0 tool licence is fine to run but check redistribution |
14
+ | `format` | Built-in: `gofmt` | - | Built-in | golangci-lint fmt (gofumpt, gci): the project's `.golangci.yml` enables formatters | - | every-pr | A `gofmt`-only check on a project whose CI enforces gofumpt or gci |
15
+ | `types` | Built-in: `go vet` | - | Built-in | staticcheck: deeper checks, normally through golangci-lint | `go vet` plus staticcheck on every PR | every-pr | `go vet` alone presented as the lint gate |
16
+ | `sast` | `golangci-lint` with `gosec` enabled | >= 2.15.0 · 2026-10-16 · active | `golangci-lint --version` · `brew install golangci-lint` | semgrep: custom rules, shared with other languages; opengrep: same rule format without the vendor rule licence; codeql: data-flow depth in CI | gosec for fast local feedback; add codeql in CI where the repository is eligible | every-pr | Scanner output as a complete audit; ignoring rule licences |
17
+ | `memory-safety` | Built-in: `-race`; `-asan` and `-msan` for cgo | - | Built-in | None | `-race` on Go tests; `-asan` or `-msan` when cgo or unsafe code is involved | every-pr | `-race` as proof of no races on paths no test runs; sanitizers on pure-Go code with no cgo |
18
+ | `dep-audit` | `govulncheck` | >= 1.9.0 · 2026-10-11 · active | `grep -F golang.org/x/vuln go.mod` · `go get -tool golang.org/x/vuln/cmd/govulncheck@latest` | osv-scanner: polyglot repositories with several lockfiles | govulncheck for reachable Go vulnerabilities and osv-scanner for the non-Go manifests | every-pr + scheduled | osv-scanner as the only Go gate, since it ignores reachability |
19
+ | `dead-code` | `deadcode` | >= 0.52.0 · 2026-10-10 · active | `grep -F golang.org/x/tools/cmd/deadcode go.mod` · `go get -tool golang.org/x/tools/cmd/deadcode@latest` | unused (golangci-lint): per-declaration, no whole-program view | `unused` in the lint run and `deadcode -test` on executables | on-demand | Deleting exported library API because one executable does not reach it |
20
+ | `unused-deps` | Built-in: `go mod tidy -diff` | - | Built-in | None | - | every-pr | Running `go mod tidy` without `-diff` in CI, which rewrites files |
21
+ | `complexity` | `golangci-lint` with `gocognit` at 15 | >= 2.15.0 · 2026-10-16 · active | `golangci-lint --version` · `brew install golangci-lint` | gocyclo: cyclomatic limit of 10-12 beside it; lizard: one metric across languages | gocognit and gocyclo together, ratcheted against a baseline | every-pr | Arbitrary limits as defects; exceptions without an owner |
22
+ | `duplication` | `golangci-lint` with `dupl` | >= 2.15.0 · 2026-10-16 · active | `golangci-lint --version` · `brew install golangci-lint` | jscpd: one report across languages | - | every-pr | Gating generated-code duplication; overlapping duplication gates |
23
+ | `api-break` | `go-apidiff` | >= 0.8.3 · 2025-05-22 · active | `grep -F joelanford/go-apidiff go.mod` · `go get -tool github.com/joelanford/go-apidiff@latest` | oasdiff: HTTP API contracts | go-apidiff on PRs and at release; it builds on `golang.org/x/exp/apidiff` | every-pr + release | `gorelease` (needs tags, slower); reporting an internal package as public |
24
+ | `docs` | Built-in: `go doc`, doc comments and `Example` functions | - | Built-in | pkgsite: browse rendered docs locally; godoclint: lint doc comments beside revive exported | Built-in docs with revive and godoclint through golangci-lint | every-pr | gomarkdoc and godocdown, which are stale; Example functions without `// Output:` |
25
+
26
+ ## Tradeoffs
27
+
28
+ ### lint
29
+
30
+ - **golangci-lint**: wins as one runner with one config and many linters; costs a GPL-3.0 tool licence and a config that drifts between major versions.
31
+ - **staticcheck**: wins for a quick standalone check; costs separate runs for every other linter.
32
+
33
+ ### sast
34
+
35
+ - **golangci-lint**: wins when gosec runs inside the lint binary you already use, with one config and fast local feedback; costs gosec's pattern-level heuristics with no data-flow analysis.
36
+ - **semgrep**: wins when custom rules are shared with other languages; costs a restrictive licence on Semgrep-maintained rules.
37
+ - **opengrep**: wins for the same rule format with no vendor rule licence; costs a younger project.
38
+ - **codeql**: wins for data-flow analysis in CI; costs a build step and a slower run.
39
+
40
+ ### complexity
41
+
42
+ - **golangci-lint**: wins when gocognit, gocyclo and the rest run in the one lint pass with a shared baseline; costs the golangci-lint config upkeep and a cognitive metric only as good as its threshold.
43
+ - **gocyclo**: wins as a second, cyclomatic limit of 10-12 beside gocognit; costs overlapping findings.
44
+ - **lizard**: wins for one metric across languages; costs a Python tool outside the Go toolchain.
45
+
46
+ ### api-break
47
+
48
+ - **oasdiff**: wins for HTTP API contracts in OpenAPI files; costs no Go symbol analysis.
49
+
50
+ ### docs
51
+
52
+ - **pkgsite**: wins for previewing rendered docs locally; costs a local server and no lint.
53
+ - **godoclint**: wins for doc-comment style rules in golangci-lint; costs a young linter that overlaps revive `exported`.
54
+
55
+ ## Language-specific
56
+
57
+ | Concern | Default | Use instead when | Avoid (why) |
58
+ | --- | --- | --- | --- |
59
+ | Cognitive complexity limit | `gocognit` at 15 in golangci-lint | The project already sets a different reviewed limit | Reporting only above 30, golangci-lint's own default. |
60
+ | Licence inventory | `go-licenses` for dependency licences | Organization-approved compliance tooling | Repository licence read as dependency compliance. |
61
+
62
+ ## Sources
63
+
64
+ - [golangci-lint](https://golangci-lint.run/docs/), [linters](https://golangci-lint.run/docs/linters/), [staticcheck](https://staticcheck.dev/), [gosec](https://pkg.go.dev/github.com/securego/gosec/v2).
65
+ - [govulncheck](https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck), [deadcode](https://pkg.go.dev/golang.org/x/tools/cmd/deadcode), [go mod tidy](https://go.dev/ref/mod#go-mod-tidy), [race detector and sanitizers](https://go.dev/doc/articles/race_detector).
66
+ - [go-apidiff](https://github.com/joelanford/go-apidiff), [apidiff](https://pkg.go.dev/golang.org/x/exp/apidiff), [pkgsite](https://pkg.go.dev/golang.org/x/pkgsite/cmd/pkgsite), [godoclint](https://github.com/godoc-lint/godoc-lint), [revive](https://github.com/mgechev/revive), [doc comments](https://go.dev/doc/comment).
@@ -0,0 +1,51 @@
1
+ # Go runtime and application helpers
2
+
3
+ Prefer supported Go toolchains, simple builds and standard-library lifecycle/concurrency primitives.
4
+
5
+ Checked 2026-11-12. Standard-library entries use Go `1.27`.
6
+
7
+ | Concern | Default | Use instead when | Avoid (why) |
8
+ | --- | --- | --- | --- |
9
+ | Supported runtime | Go `1.27` | Supported Go `1.26` for compatibility; libraries retain a supported required minimum | Unsupported toolchains or shipped binaries not rebuilt after security fixes. |
10
+ | Packaging/build | Go modules, `go.mod`, `go.sum`, native build tools; standard toolchain is sufficient | Project build orchestration for real multi-step needs | Dependency solely for a native toolchain capability. |
11
+ | Monorepos | Native `go.work`, modules and `internal/`; standard toolchain is sufficient | Existing repository orchestration | Multiple modules without an ownership/release boundary; workspace-only success mistaken for published-module correctness. |
12
+ | Containers | Pure-Go binary with `CGO_ENABLED=0`, digest-pinned nonroot distroless/static or Chainguard static | Compatible native-library/base image for CGO workloads | Static image for dynamically linked DuckDB/libvips binaries. |
13
+ | CPU/memory | Container-aware Go runtime plus explicit `GOMEMLIMIT`; standard runtime is sufficient | `go.uber.org/automaxprocs` `>= 1` for older runtimes/compatibility configs | Automatic dependency on supported current runtimes; memory limit as hard RSS cap. |
14
+ | Shutdown | `signal.NotifyContext`, new bounded shutdown context and `http.Server.Shutdown`; standard library is sufficient | Explicit worker/connection drain hooks | Already-canceled signal context for shutdown; forgetting hijacked/WebSocket connections. |
15
+ | Binary releases | `github.com/goreleaser/goreleaser/v2` `>= 2` when distributing binaries | `github.com/google/ko` `>= 0.19` for straightforward Go container builds | Assuming a simple pure-Go container path covers arbitrary CGO/OS libraries. |
16
+ | Documentation | Go doc comments and executable examples; standard toolchain is sufficient | `golang.org/x/pkgsite` `>= 0.6` for local browsing | Separate documentation generator without a named gap. |
17
+ | HTTP client | Shared `net/http.Client`/transport, explicit deadlines and body closure; standard library is sufficient | `github.com/hashicorp/go-retryablehttp` `>= 0.7` for needed retries; `resty.dev/v3` `>= 3` prerelease for evaluated REST ergonomics | Resty v3 described as stable; non-idempotent replay without safeguards. |
18
+ | Retry/backoff | SDK-native retries or bounded explicit policy | `github.com/cenkalti/backoff/v5` `>= 5` for reusable backoff | Nested retries, no overall deadline/jitter or repeated side effects. |
19
+ | Circuit breaker | No breaker unless failure-isolation need exists | `github.com/sony/gobreaker/v2` `>= 2` for a defined dependency policy | Universal breaker boilerplate; retry/breaker ordering left untested. |
20
+ | Rate limiting | `golang.org/x/time/rate` `>= 0.16` for token buckets | `github.com/go-chi/httprate` `>= 0.16` for HTTP limits; shared-store limiter for fleet quotas | Process-local quotas advertised as global. |
21
+ | Concurrency | `context`, channels, `sync`, `sync.WaitGroup.Go`; standard library is sufficient for simple coordination | `golang.org/x/sync/errgroup` `>= 0.25` for cancellation/errors; `github.com/sourcegraph/conc` `>= 0.3` for pool/result ergonomics | Unbounded goroutines; assuming WaitGroup propagates errors; calling conc abandoned solely from its tag. |
22
+ | Errors | `fmt` wrapping, `errors.Is`, `As`, `AsType`, `Join`; standard library is sufficient | `github.com/cockroachdb/errors` `>= 1` for stack/redaction/diagnostic transport requirements | New `github.com/pkg/errors` `>= 0.9` adoption without a gap; incorrect claims it is archived. |
23
+ | Date/time | `time`; standard library is sufficient | Domain-specific types for date-only/business calendars | Custom clock/date abstraction without a real domain/test need. |
24
+ | IDs | `uuid` v4/v7; standard library is sufficient in Go `1.27` | `github.com/google/uuid` `>= 1` for older toolchains/existing types; `github.com/oklog/ulid/v2` `>= 2` for ULID contracts | Sortable IDs as secrets or authorization. |
25
+ | Feature flags | `github.com/open-feature/go-sdk` `>= 1` for applications/services/CLIs; flags.yaml: contrib `providers/flagd` `>= 0.8`, `WithOfflineFilePath` (`.yaml`, `.yml`, `.json`) | SSM: contrib `providers/aws-ssm` `>= 1.0`; AppConfig: third-party `github.com/Arthur1/openfeature-provider-go-aws-appconfig` `>= 0.4`, Agent only, boolean flags, review dependency | Ask before writing a missing provider; libraries take caller decisions, harness plugins keep options; see `quality-code-design`'s `feature-flags.md`. |
26
+ | Dependency injection | Manual constructor wiring; standard language features are sufficient | `go.uber.org/fx` `>= 1` for lifecycle/container; `go.uber.org/dig` `>= 1` for lower-level DI | New Google Wire adoption: archived and explicitly unmaintained. |
27
+ | State machines | Explicit states/transitions for small models; standard language features are sufficient | `github.com/looplab/fsm` `>= 1` for event transitions; `github.com/qmuntal/stateless` `>= 1` for hierarchical/guarded models | Framework machinery for a tiny switch. |
28
+ | Collections/helpers | `slices`, `maps`, `iter`, built-in collections; standard library is sufficient | `github.com/samber/lo` `>= 1` for useful missing helpers | Blanket utility imports or bespoke collections without ordering/concurrency requirements. |
29
+ | Formatting/static tooling | Native formatter plus configured `golangci-lint` `>= 2` | `mvdan.cc/gofumpt` `>= 0.12` for stricter team style; `golang.org/x/tools/gopls` `>= 0.24` for editor analysis | Obsolete lint config; commands duplicated from `lang-go-quality`. |
30
+
31
+ ## Rules
32
+
33
+ - Recent standard-library features replace common dependencies:
34
+ - Go `1.22`: method/wildcard routing.
35
+ - Go `1.23`: iterators.
36
+ - Go `1.24`: rooted filesystem and crypto additions.
37
+ - Go `1.25`: stable synctest and WaitGroup helpers.
38
+ - Go `1.26`: error helpers and modernizing fixes.
39
+ - Go `1.27`: JSON v2 without experimental opt-in, and UUID v4/v7.
40
+ - Preserve existing wire contracts when changing codecs.
41
+ - Pin toolchains, runtime/native dependencies and build inputs. Test the actual deployment architecture/image, not only the developer host.
42
+ - Check module layout/build commands in `lang-go-packaging` and `lang-go-quality`; testing commands in `lang-go-testing`; benchmark methodology in `lang-go-profiling`.
43
+ - Use explicit lifecycle ownership and bounded drain/flush for HTTP, workers, connections and telemetry.
44
+
45
+ ## Sources
46
+
47
+ - [Supported Go releases](https://go.dev/doc/devel/release), [Go 1.27](https://go.dev/doc/go1.27), [Go 1.25 runtime](https://go.dev/doc/go1.25#runtime), [memory limit](https://pkg.go.dev/runtime/debug#SetMemoryLimit), [workspaces](https://go.dev/doc/tutorial/workspaces).
48
+ - [Distroless](https://github.com/GoogleContainerTools/distroless), [Chainguard static](https://images.chainguard.dev/directory/image/static/overview), [GoReleaser](https://pkg.go.dev/github.com/goreleaser/goreleaser/v2), [ko](https://pkg.go.dev/github.com/google/ko), [doc comments](https://go.dev/doc/comment), [pkgsite](https://pkg.go.dev/golang.org/x/pkgsite).
49
+ - [HTTP client/shutdown](https://pkg.go.dev/net/http), [signals](https://pkg.go.dev/os/signal#NotifyContext), [retryablehttp](https://pkg.go.dev/github.com/hashicorp/go-retryablehttp), [Resty prerelease](https://pkg.go.dev/resty.dev/v3), [backoff](https://pkg.go.dev/github.com/cenkalti/backoff/v5), [breaker](https://pkg.go.dev/github.com/sony/gobreaker/v2), [rate](https://pkg.go.dev/golang.org/x/time/rate), [httprate](https://pkg.go.dev/github.com/go-chi/httprate).
50
+ - [errgroup](https://pkg.go.dev/golang.org/x/sync/errgroup), [conc](https://github.com/sourcegraph/conc), [errors](https://pkg.go.dev/errors), [UUID](https://pkg.go.dev/uuid), [ULID](https://pkg.go.dev/github.com/oklog/ulid/v2), [OpenFeature](https://pkg.go.dev/github.com/open-feature/go-sdk).
51
+ - [Wire archive](https://github.com/google/wire), [Fx](https://pkg.go.dev/go.uber.org/fx), [Dig](https://pkg.go.dev/go.uber.org/dig), [FSM](https://pkg.go.dev/github.com/looplab/fsm), [Stateless](https://pkg.go.dev/github.com/qmuntal/stateless), [collections](https://pkg.go.dev/slices), [lo](https://pkg.go.dev/github.com/samber/lo), [golangci](https://pkg.go.dev/github.com/golangci/golangci-lint/v2).
@@ -0,0 +1,40 @@
1
+ # Go security and code audits
2
+
3
+ Use standard cryptographic primitives, explicit boundary policies and complementary scanners with reviewed findings.
4
+
5
+ Checked 2026-11-16. SAST, dependency audit, dead code, complexity and duplication moved to [quality.md](quality.md). Standard-library entries use Go `1.27`; commands belong in `lang-go-quality`.
6
+
7
+ | Concern | Default | Use instead when | Avoid (why) |
8
+ | --- | --- | --- | --- |
9
+ | Cryptography/randomness | `crypto`, `crypto/rand`, `crypto/tls`; standard library is sufficient for supplied primitives | `golang.org/x/crypto` `>= 0.59` for missing approved algorithms | Homemade crypto, `math/rand` for secrets or bypassed TLS verification. |
10
+ | Password storage | `golang.org/x/crypto/argon2` `>= 0.59` Argon2id with reviewed parameters | `golang.org/x/crypto/bcrypt` `>= 0.59` for compatibility | Plain/fast hashes; bcrypt passwords beyond its `72`-byte limit. |
11
+ | JWT/JOSE | `github.com/golang-jwt/jwt/v5` `>= 5` for verification | `github.com/lestrrat-go/jwx/v3` `>= 3` for JWK/JWE/JWS and cached keys | Decode-only authentication; unbounded key fetching or absent algorithm/issuer/audience/time checks. |
12
+ | OAuth/OIDC | `golang.org/x/oauth2` `>= 0.38`, `github.com/coreos/go-oidc/v3` `>= 3` | Provider integration for a named flow | Handwritten OAuth protocols or identity tokens used as API access tokens. |
13
+ | Secrets | Workload identity and managed-secret retrieval, detailed in `aws.md` | Existing approved secret manager | Values in source, fixtures, errors, logs or telemetry; env vars mistaken for secure storage. |
14
+ | Filesystem containment | `os.Root`; standard library is sufficient for its rooted operations | Reviewed sandbox/process isolation for stronger threat models | String-prefix path checks as a race-safe filesystem boundary. |
15
+ | SSRF | Restricted `net/http.Transport`/dialer plus destination policy; standard library supplies the mechanism and the application enforces the policy | Network egress proxy/controls | Hostname-only checks, DNS-check-then-redial, unrestricted redirects/proxies; validate actual IPv4/IPv6/mapped dial addresses. |
16
+ | HTML/input | `html/template` escaping for ordinary output | `github.com/microcosm-cc/bluemonday` `>= 1` for allowlisted rich HTML | Regex sanitizers or decoding treated as validation. |
17
+ | CSRF | `net/http.CrossOriginProtection`; standard library suffices for origin-based protection | `github.com/gorilla/csrf` `>= 1` for synchronizer-token requirements | Assuming origin checks and token mechanisms are identical. |
18
+ | Security headers | Explicit `net/http` headers; standard library is sufficient | `github.com/unrolled/secure` `>= 1` for configurable shared middleware | Blind CSP/HSTS defaults; CORS as authorization. |
19
+ | Secret scanning | Offline `Betterleaks` `>= 1` or `Gitleaks` `>= 8` on changed content | `TruffleHog` `>= 3` for separate history/verification scans | Verified-only policy that drops unverifiable secrets. |
20
+ | SBOM | `github.com/CycloneDX/cyclonedx-gomod` `>= 1` for Go source modules | `Syft` `>= 1` for images/artifacts; `cdxgen` `>= 13` for multilingual source | SBOM generation presented as vulnerability detection. |
21
+ | Dependency licences | `go-licenses` `>= 2` inventory and project policy | Organization-approved compliance tooling | Repository-licence detection as equivalent to dependency compliance. |
22
+ | Container security | Verified `Grype` `>= 0.121` plus `Syft` `>= 1` when images ship | `Trivy` `>= 0.76` only with explicit artifact/transitive-action review | Ignoring Trivy's documented March 2026 compromise or trusting mutable installer tags. |
23
+ | Workflow security | `actionlint` `>= 1`, `zizmor` `>= 1`, `pinact` `>= 5` when workflows exist | Scheduled Scorecard `5` assessment for repository posture | Treating an action SHA alone as proof of downloaded-tool integrity. |
24
+
25
+ ## Rules
26
+
27
+ - Authorize tenant/object/action/field access in the domain boundary, not only at the gateway. Bound bodies, decompression, queries, concurrency and outbound waits.
28
+ - Distinguish escaping, sanitization, CSRF, SSRF, SAST, SCA and SBOM purposes. No one scanner supplies all of them.
29
+ - Pin scanner artifacts in CI. Review suppressions with an owner, rationale and expiry; configure one tool per gate.
30
+ - Keep a single dependency updater, such as `Renovate` `>= 44`, with project cooldown and vulnerability policy. Review supply-chain and license changes alongside advisories.
31
+ - Dead code, duplication, SAST and dependency audit rules are in [quality.md](quality.md); report dead code and duplication before gating a mature codebase.
32
+
33
+ ## Sources
34
+
35
+ - [Go crypto additions](https://go.dev/doc/go1.24), [Argon2](https://pkg.go.dev/golang.org/x/crypto/argon2), [bcrypt](https://pkg.go.dev/golang.org/x/crypto/bcrypt), [JWT](https://pkg.go.dev/github.com/golang-jwt/jwt/v5), [JOSE](https://pkg.go.dev/github.com/lestrrat-go/jwx/v3), [rooted files](https://pkg.go.dev/os#Root).
36
+ - [HTTP/dial policy mechanisms](https://pkg.go.dev/net/http), [dialer](https://pkg.go.dev/net#Dialer), [CSRF additions](https://go.dev/doc/go1.25#nethttp), [Gorilla CSRF](https://pkg.go.dev/github.com/gorilla/csrf), [secure headers](https://pkg.go.dev/github.com/unrolled/secure).
37
+ - [gosec](https://pkg.go.dev/github.com/securego/gosec/v2), [Go vulnerability tooling](https://go.dev/security/vuln/), [govulncheck](https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck), [golangci linters](https://golangci-lint.run/docs/linters/), [deadcode](https://pkg.go.dev/golang.org/x/tools/cmd/deadcode).
38
+ - [Opengrep](https://github.com/opengrep/opengrep), [Semgrep rule-license changes](https://semgrep.dev/blog/2024/important-updates-to-semgrep-oss), [Betterleaks](https://github.com/betterleaks/betterleaks), [Gitleaks](https://github.com/gitleaks/gitleaks), [TruffleHog](https://github.com/trufflesecurity/trufflehog).
39
+ - [OSV](https://github.com/google/osv-scanner), [CycloneDX Go](https://pkg.go.dev/github.com/CycloneDX/cyclonedx-gomod), [Syft](https://github.com/anchore/syft), [cdxgen](https://github.com/cdxgen/cdxgen), [go-licenses](https://github.com/google/go-licenses), [Grype](https://github.com/anchore/grype), [Trivy incident](https://github.com/aquasecurity/trivy/security/advisories/GHSA-69fq-xp46-6x23).
40
+ - [jscpd](https://github.com/kucherenko/jscpd), [PMD](https://github.com/pmd/pmd), [actionlint](https://github.com/rhysd/actionlint), [zizmor](https://github.com/zizmorcore/zizmor), [pinact](https://github.com/suzuki-shunsuke/pinact), [Renovate](https://github.com/renovatebot/renovate).
@@ -0,0 +1,53 @@
1
+ # Go services and content
2
+
3
+ Use these choices for network boundaries and generated or rendered content; use `toolchain-api` for API design.
4
+
5
+ Checked 2026-11-12. Standard-library entries use Go `1.27`.
6
+
7
+ | Concern | Default | Use instead when | Avoid (why) |
8
+ | --- | --- | --- | --- |
9
+ | Server and ordinary routing | `net/http`, `http.ServeMux`; standard library is sufficient | `github.com/go-chi/chi/v5` `>= 5` for groups, mounting and route-local middleware | A router dependency solely for method/wildcard matching, supplied since Go `1.22`. |
10
+ | Framework | No framework beyond `net/http` | `github.com/labstack/echo/v5` `>= 5` or `github.com/gin-gonic/gin` `>= 1` for established team conventions | `github.com/gofiber/fiber/v3` `>= 3` without measured need and a fasthttp interoperability/lifetime audit. |
11
+ | Middleware composition | `func(http.Handler) http.Handler`; standard library is sufficient | Chi `5` middleware with its router; framework hooks within an existing framework | Per-handler copies of auth, telemetry or error translation. |
12
+ | CORS | No CORS for same-origin services | `github.com/rs/cors` `>= 1` for cross-origin browser clients | Wildcard origins with credentials; confusing CORS with authorization. |
13
+ | Recovery, request IDs and access logs | Boundary middleware using `net/http` and `log/slog` | Chi `5` middleware when already installed | Chi `5` deprecated `RealIP`: spoofing risk; trust only configured proxies. |
14
+ | Timeouts and rate limits | `http.Server` deadlines, request `context`; `golang.org/x/time/rate` `>= 0.16` | Shared-store limits for multiple replicas; streaming-specific deadlines | Blanket buffered timeout wrappers around SSE/WebSockets; process-local limits advertised as global. |
15
+ | Request validation | Explicit checks for small types; standard library is sufficient | `github.com/go-playground/validator/v10` `>= 10` for shared struct-tag rules; Huma `2` for schema validation | Treating decoding, generated types or tags as domain authorization. |
16
+ | Code-first OpenAPI | `github.com/danielgtaylor/huma/v2` `>= 2` when schema generation is needed | Plain `net/http` for endpoints without generated contracts | Hand-maintaining separate schemas and handlers that can drift. |
17
+ | Schema-first OpenAPI | `github.com/oapi-codegen/oapi-codegen/v2` `>= 2` for ordinary handler integration | `github.com/ogen-go/ogen` `>= 1` for generated client/server infrastructure | Old `deepmap` imports; assuming all generated handlers validate automatically. |
18
+ | Protobuf runtime | `google.golang.org/protobuf` `>= 1` | Existing generated runtime during a planned migration | Mixing incompatible generated files, compiler plugins and runtimes. |
19
+ | HTTP-native RPC | `connectrpc.com/connect/v2` `>= 2` (`connectrpc.com/connect` `>= 1` in existing code) | `google.golang.org/grpc` `>= 1` for native gRPC infrastructure/features | Bespoke RPC framing; assuming browser bidirectional streams work like native HTTP/2. |
20
+ | RPC middleware | Connect `2` interceptors; gRPC `1` interceptors/stats handlers | `github.com/grpc-ecosystem/go-grpc-middleware/v2` `>= 2` for reusable gRPC chains | Duplicate instrumentation or mismatched unary/stream policy. |
21
+ | GraphQL | `github.com/99designs/gqlgen` `>= 0.17` for schema-first generated resolvers | `github.com/graphql-go/graphql` `>= 0.8` for existing runtime-schema integrations | GraphQL without per-resolver auth, cost limits and N+1 controls. |
22
+ | WebSockets | `github.com/coder/websocket` `>= 1` | `github.com/gorilla/websocket` `>= 1` for existing integrations | Old `nhooyr.io/websocket` imports; claiming Gorilla is still archived. |
23
+ | SSE | `net/http`, flushing and request cancellation; standard library is sufficient | A replay/subscription layer when resumable delivery is required | WebSockets for one-way notifications; untested proxy buffering and reconnect behavior. |
24
+ | JWT | `github.com/golang-jwt/jwt/v5` `>= 5` for signed-token verification | `github.com/lestrrat-go/jwx/v3` `>= 3` for JWK/JWE/JWS requirements | Decoding without signature, issuer, audience, expiry and algorithm checks. |
25
+ | OAuth/OIDC | `golang.org/x/oauth2` `>= 0.38`; `github.com/coreos/go-oidc/v3` `>= 3` for discovery and verification | Existing provider SDK when its integration supplies required behavior | Custom OAuth flows or accepting an ID token as an API access token. |
26
+ | HTML templates | `html/template`; standard library is sufficient | `github.com/a-h/templ` `>= 0.3` for compiled typed components | `text/template` for untrusted HTML; marking user strings trusted. |
27
+ | HTML sanitization | Plain text and escaping when rich HTML is unnecessary | `github.com/microcosm-cc/bluemonday` `>= 1` for an allowlisted rich-HTML policy | Regex sanitizers; treating escaping as sanitization. |
28
+ | Markdown | `github.com/yuin/goldmark` `>= 1` | Required extensions with explicit sanitization | Raw HTML output without a trust policy. |
29
+ | PDF | `github.com/johnfercher/maroto/v2` `>= 2` for programmatic reports | Browser rendering for CSS-heavy documents | Archived `github.com/jung-kurt/gofpdf` for new projects. |
30
+ | Images | `image`, `image/png`, `image/jpeg`; standard library is sufficient for codecs | `github.com/disintegration/imaging` `>= 1` for transforms; `github.com/davidbyttow/govips/v2` `>= 2` for measured libvips workloads | Native dependencies without need; unbounded image dimensions or decompression. |
31
+ | Email | `github.com/wneessen/go-mail` `>= 0.8` for SMTP/MIME | Provider SDK/API for managed delivery | New message-building systems on frozen `net/smtp` alone. |
32
+
33
+ ## Rules
34
+
35
+ - Put request context and OTel outside middleware that emits correlated logs. Apply authorization before business handlers; place recovery so it catches inner failures and instrumentation still observes the outcome.
36
+ - Treat body limits, authentication, validation and error translation as boundary concerns. Test ordering and failure paths rather than copying one universal middleware order.
37
+ - Preserve optional response interfaces when wrapping writers. Test flushing, hijacking, compression and cancellation on streaming endpoints.
38
+ - Put telemetry and retry behavior in shared client transports. Do not add a retry loop inside each handler.
39
+ - Use `http.RoundTripper` for client middleware; establish retry/auth/tracing ordering and safe body replay. The standard library mechanism is sufficient.
40
+ - Keep one framework per HTTP surface. Reuse the same `net/http` handler and middleware on Lambda through Web Adapter or an `aws-lambda-go` HTTP adapter.
41
+ - Use `quality-code-design` and `middleware.md` for the language-neutral composition rules.
42
+ - Use validator `10` with `WithRequiredStructEnabled` for its recommended struct behavior. Keep business invariants explicit.
43
+ - Pin the Protobuf compiler and generation plugins together; use Buf's `v2` configuration for reproducible generation and compatibility gates. The configuration version is not the CLI major. See `toolchain-api` for the workflow.
44
+ - Connect `2` (2.0.2, October 2026) changed interceptor and handler APIs; follow the `v2` documentation and migrate `v1` code deliberately.
45
+
46
+ ## Sources
47
+
48
+ - [Standard HTTP](https://pkg.go.dev/net/http), [Chi](https://pkg.go.dev/github.com/go-chi/chi/v5), [Echo](https://pkg.go.dev/github.com/labstack/echo/v5), [Fiber caveats](https://docs.gofiber.io/), [CORS](https://pkg.go.dev/github.com/rs/cors).
49
+ - [Validator](https://pkg.go.dev/github.com/go-playground/validator/v10), [Huma](https://pkg.go.dev/github.com/danielgtaylor/huma/v2), [oapi-codegen](https://pkg.go.dev/github.com/oapi-codegen/oapi-codegen/v2), [ogen](https://pkg.go.dev/github.com/ogen-go/ogen).
50
+ - [Connect](https://pkg.go.dev/connectrpc.com/connect), [gRPC](https://pkg.go.dev/google.golang.org/grpc), [Protobuf](https://pkg.go.dev/google.golang.org/protobuf), [gRPC middleware](https://pkg.go.dev/github.com/grpc-ecosystem/go-grpc-middleware/v2), [gqlgen](https://pkg.go.dev/github.com/99designs/gqlgen).
51
+ - [Coder WebSocket](https://pkg.go.dev/github.com/coder/websocket), [Gorilla](https://github.com/gorilla/websocket), [JWT](https://pkg.go.dev/github.com/golang-jwt/jwt/v5), [JOSE](https://pkg.go.dev/github.com/lestrrat-go/jwx/v3), [OIDC](https://pkg.go.dev/github.com/coreos/go-oidc/v3), [OAuth](https://pkg.go.dev/golang.org/x/oauth2).
52
+ - [HTML templates](https://pkg.go.dev/html/template), [templ](https://pkg.go.dev/github.com/a-h/templ), [Bluemonday](https://pkg.go.dev/github.com/microcosm-cc/bluemonday), [Goldmark](https://pkg.go.dev/github.com/yuin/goldmark).
53
+ - [Maroto](https://pkg.go.dev/github.com/johnfercher/maroto/v2), [archived PDF library](https://github.com/jung-kurt/gofpdf), [images](https://pkg.go.dev/image), [imaging](https://pkg.go.dev/github.com/disintegration/imaging), [govips](https://pkg.go.dev/github.com/davidbyttow/govips/v2), [mail](https://pkg.go.dev/github.com/wneessen/go-mail).
@@ -0,0 +1,73 @@
1
+ # Go testing libraries
2
+
3
+ Use the standard testing stack first and add specialized tools for the behavior being verified.
4
+ See `lang-go-testing`'s [practice reference](../../lang-go-testing/references/practice.md)
5
+ for Go idioms and tool choices; use `quality-testing` for suite design and maintenance.
6
+
7
+ Checked 2026-11-16.
8
+
9
+ Standard-library entries use Go `1.27`; commands belong in `lang-go-testing` and `lang-go-quality`. Install policy: detect the tool, recommend the install, ask before running it (`toolchain-languages` `concerns.md`). Shared tools: `shared-tools.md` in `toolchain-languages`.
10
+
11
+ ## Concerns
12
+
13
+ | Concern | Default | Maintenance | Install | Alternatives | Use both when | Run | Avoid |
14
+ | --- | --- | --- | --- | --- | --- | --- | --- |
15
+ | `test-runner` | Built-in: `go test` | - | Built-in | gotestsum: JUnit XML and readable output for CI | `go test` produces the results; gotestsum wraps it when CI needs JUnit | every-pr | `--rerun-fails` as a gate; it hides intermittent defects |
16
+ | `assertions` | Built-in: `testing` package plus `github.com/google/go-cmp` (`cmp.Diff`) as the one diff helper | >= 0.7.0 · 2025-02-21 · active | `grep google/go-cmp go.mod` · `go get github.com/google/go-cmp@latest` | testify 1.12.1 (2026-08-19) or matryer/is: the project already uses it, so keep it | - | every-pr | Ginkgo/Gomega in new code (DSL, not plain tests); mixing two assertion libraries |
17
+ | `watch` | `gotestsum --watch` (Apache-2.0) | >= 1.13.0 · 2025-09-11 · active | `gotestsum --version` · `go install gotest.tools/gotestsum@latest` | watchexec 2.8.0: language-agnostic watching | Built-in `go test` caching for test selection | on-demand | Watching with `-count=1`, which defeats cache-based selection |
18
+ | `property` | `pgregory.net/rapid` | >= 1.3.0 · 2026-04-30 · active | `grep pgregory.net/rapid go.mod` · `go get pgregory.net/rapid@latest` | gopter: existing suites only; testing/quick: frozen, trivial checks only | - | every-pr | Random inputs without a stated invariant; keeping failing seeds out of the repository |
19
+ | `fuzz` | Built-in: `go test -fuzz` | - | Built-in | None | - | bounded-pr | Unbounded `-fuzztime` on a PR; discarding `testdata/fuzz` failures |
20
+ | `fuzz-continuous` | Shared: oss-fuzz | - | Shared | clusterfuzzlite: private repositories or PR-time campaigns | oss-fuzz for the long campaign and clusterfuzzlite for the PR when both are eligible | scheduled | Fuzz targets that are not built with `compile_native_go_fuzzer` |
21
+ | `mutation` | `gremlins` | >= 0.6.0 · 2025-12-06 · pre-1.0 | `grep -F go-gremlins/gremlins go.mod` · `go get -tool github.com/go-gremlins/gremlins/cmd/gremlins@latest` | go-mutesting (avito-tech v2): gremlins cannot parse the code | - | diff-pr + scheduled | Whole-module mutation as a blocking PR gate; assuming Go 1.27 generic-method syntax is supported (unverified) |
22
+ | `snapshot` | Built-in: golden files in `testdata` | - | Built-in | gotest.tools/v3/golden: update flag and diff helper; goldie: template and fixture-dir helpers | - | every-pr | Automatic update in CI; unreviewed bulk regeneration |
23
+ | `component` | N/A: no UI component model | - | - | None | - | every-pr | - |
24
+ | `concurrency` | Built-in: `-race` and `testing/synctest` | - | Built-in | goleak: assert no goroutine outlives a test; goroutineleak profile: with Go 1.27 runtime/pprof, inspect leaks in a running process | `-race`, `synctest` and goleak together on concurrent code | every-pr | Sleep-based synchronization; synctest as a substitute for network integration |
25
+ | `coverage` | Built-in: `go test -coverprofile` | - | Built-in | None | - | every-pr | A percentage target; statement coverage read as branch coverage |
26
+ | `benchmark` | Built-in: `testing.B` with `b.Loop` | - | Built-in | benchstat: compare repeated runs | `go test -bench -count=10` output goes through benchstat before any claim | on-demand | One noisy run as proof; mixing `b.Loop` with `b.N` |
27
+ | `flaky-order` | Built-in: `-shuffle=on -count=N` | - | Built-in | gotestsum: `--rerun-fails` for diagnosis only | - | scheduled | Retries on by default; quarantine without an owner and expiry |
28
+ | `integration` | Shared: testcontainers | - | Shared | None | - | every-pr | Driver mocks presented as proof of SQL, transaction or broker behaviour |
29
+ | `contract` | Shared: contracts | - | Shared | pact-go 2.9.0: two or more services you own call each other and deploy independently (Pact Broker required, and the native pact_ffi install) | - | every-pr | Pact as the only gate for public APIs; skipping the native `pact_ffi` install that pact-go 2 needs |
30
+ | `api-schema` | Shared: schemathesis | - | Shared | None | - | bounded-pr + scheduled | Running against production; archived Dredd |
31
+ | `load` | Shared: k6 | - | Shared | vegeta: constant-rate HTTP attacks from Go code or the CLI, with no AGPL-3.0 licence to weigh | - | scheduled | One throughput number as capacity |
32
+
33
+ ## Tradeoffs
34
+
35
+ ### property
36
+
37
+ - **pgregory.net/rapid**: wins on automatic shrinking, stateful testing and `go test` integration with saved failing seeds; costs a dependency and generators to learn.
38
+ - **gopter**: wins when a suite already uses it; costs no release since 2020.
39
+ - **testing/quick**: wins for a one-line check with no dependency; costs a frozen package with no shrinking.
40
+
41
+ ### snapshot
42
+
43
+ - **gotest.tools/v3/golden**: wins when the project already uses gotest.tools and wants a `-test.update-golden` flag; costs a dependency and a fixed file layout.
44
+ - **goldie**: wins for templated or per-directory fixtures; costs a dependency and its own update flag.
45
+
46
+ ### concurrency
47
+
48
+ - **goleak**: wins when a test must fail on a leaked goroutine; costs a dependency and noise from background goroutines that need ignore options.
49
+ - **goroutineleak profile**: wins for leaks in a live service via `runtime/pprof`; costs a profile read by hand rather than a test assertion.
50
+
51
+ ## Language-specific
52
+
53
+ | Concern | Default | Use instead when | Avoid (why) |
54
+ | --- | --- | --- | --- |
55
+ | Unit tests | `testing`, table tests and subtests; standard library is sufficient | Assertions: see the `assertions` row | A test framework solely to wrap basic checks. |
56
+ | HTTP mocks | `net/http/httptest`, controlled servers and small fakes; standard library is sufficient | `github.com/dnaeon/go-vcr/v4` for recordings against external APIs | Real internet in unit tests; credentials or PII in fixtures. |
57
+ | Interface mocks | Small consumer-owned fakes | `go.uber.org/mock` for generated expectations; `github.com/vektra/mockery/v3` for testify-oriented mocks | Archived `github.com/golang/mock`; implementation-detail expectations. |
58
+ | Factories/data | Explicit fixture functions and typed literals; standard library is sufficient | Rapid generators for property testing | A global randomized factory hiding critical fields. |
59
+ | AWS integration | Typed events and SDK-facing fakes for units | DynamoDB Local or LocalStack for selected behaviour, then isolated cloud tests | Emulator-only claims about IAM, retries, batching and concurrency. |
60
+ | Telemetry | OTel SDK in-memory trace facilities and signal readers | Real collector or backend smoke test for export wiring | Random ID or time assertions; missing failure and secret checks. |
61
+
62
+ ## Rules
63
+
64
+ - Test business invariants directly; test adapters, middleware order, early exits, cancellation and streaming separately.
65
+ - Preserve first-attempt failure evidence. Retries diagnose flakes rather than erase them; quarantines need ownership and expiry.
66
+ - Bound normal-CI fuzz and load work. Run longer campaigns separately. Keep fixtures reviewed and secret-free.
67
+ - Mutation: scope with `gremlins unleash --diff <ref> --output=<json>`. Neither Gremlins nor go-mutesting emits the Stryker schema; `quality_test_compare` reads the Gremlins JSON.
68
+
69
+ ## Sources
70
+
71
+ - [testing](https://pkg.go.dev/testing), [synctest](https://pkg.go.dev/testing/synctest), [httptest](https://pkg.go.dev/net/http/httptest), [fuzzing](https://go.dev/doc/security/fuzz/), [go-cmp](https://pkg.go.dev/github.com/google/go-cmp), [Rapid](https://pkg.go.dev/pgregory.net/rapid).
72
+ - [Golden helpers](https://pkg.go.dev/gotest.tools/v3/golden), [Goldie](https://pkg.go.dev/github.com/sebdah/goldie/v2), [recordings](https://pkg.go.dev/github.com/dnaeon/go-vcr/v4), [Uber mocks](https://pkg.go.dev/go.uber.org/mock), [Mockery](https://pkg.go.dev/github.com/vektra/mockery/v3), [Testcontainers](https://pkg.go.dev/github.com/testcontainers/testcontainers-go).
73
+ - [Pact](https://pkg.go.dev/github.com/pact-foundation/pact-go/v2), [Schemathesis](https://github.com/schemathesis/schemathesis), [Vegeta](https://pkg.go.dev/github.com/tsenart/vegeta/v12), [k6 CLI](https://github.com/grafana/k6/releases), [Gremlins](https://pkg.go.dev/github.com/go-gremlins/gremlins), [go-mutesting](https://github.com/avito-tech/go-mutesting), [goleak](https://pkg.go.dev/go.uber.org/goleak), [runtime/pprof](https://pkg.go.dev/runtime/pprof), [benchstat](https://pkg.go.dev/golang.org/x/perf/cmd/benchstat), [telemetry tests](https://pkg.go.dev/go.opentelemetry.io/otel/sdk/trace/tracetest).