Generated: 2026-04-02 | Commit: cea3379a2 | Branch: master
Go microservice framework (github.com/beatlabs/patron, Go 1.24). Component-based architecture: Service orchestrates lifecycle + observability; Component implementations handle sync/async processing; client/ wraps external services. 153 source files, ~21K LOC.
patron/
├── service.go, options.go, doc.go # Service entry point + functional options
├── component/ # Server-side processing (see component/http/AGENTS.md)
│ ├── http/ # HTTP server (routes, middleware, cache, auth, router)
│ ├── kafka/ # Kafka consumer (franz-go)
│ ├── amqp/ # RabbitMQ consumer (amqp091-go)
│ ├── grpc/ # gRPC server
│ └── sqs/ # AWS SQS consumer
├── client/ # Client wrappers (see client/AGENTS.md)
│ ├── http/, grpc/, kafka/, amqp/ # Protocol clients
│ ├── sqs/, sns/ # AWS clients (SDK v2)
│ ├── sql/, redis/, mongo/, es/ # Data store clients
│ └── mqtt/ # MQTT publisher
├── observability/ # OTel setup (see observability/AGENTS.md)
│ ├── log/ # slog helpers
│ ├── trace/ # Tracing helpers
│ └── metric/ # Metrics helpers
├── cache/ # Cache interfaces + impls (see cache/AGENTS.md)
├── reliability/ # Circuit breaker + retry (see reliability/AGENTS.md)
├── correlation/ # X-Correlation-Id propagation
├── encoding/ # JSON + protobuf codecs
├── examples/ # Service + client examples (e2e tested in CI)
├── internal/ # Test helpers + validation utils
└── docs/ # API docs per component/client
| Task | Location | Notes |
|---|---|---|
| Add new component | component/<protocol>/ |
Implement Component interface (Run(ctx) error) |
| Add new client | client/<service>/ |
Follow functional options pattern, add OTel instrumentation |
| HTTP routes/middleware | component/http/ |
See component/http/AGENTS.md |
| Observability changes | observability/ |
See observability/AGENTS.md |
| Cache implementations | cache/ |
See cache/AGENTS.md |
| Reliability patterns | reliability/ |
See reliability/AGENTS.md |
| Breaking changes | BREAKING.md |
Document migration path |
| CI pipeline | .github/workflows/ci.yml |
Lint → format check → integration tests → e2e |
| Symbol | Type | Location | Role |
|---|---|---|---|
Service |
struct | service.go:31 |
Orchestrates components + observability lifecycle |
Component |
interface | service.go:25 |
Run(context.Context) error — all components implement this |
New |
func | service.go:41 |
patron.New(name, version, opts...) — creates Service |
OptionFunc |
func | options.go:9 |
Functional option pattern for Service config |
WithSIGHUP |
func | options.go:12 |
Register SIGHUP handler |
WithLogFields |
func | options.go:26 |
Add default log fields |
WithJSONLogger |
func | options.go:46 |
Switch to JSON log output |
task # Run tests (default)
task test # go test ./... -cover -race -timeout 60s
task testint # Integration tests (-tags=integration), needs `task deps-start`
task lint # golangci-lint (requires v2.6.1 installed)
task deeplint # Deep lint analysis
task fmt # go fmt
task fmtcheck # Check formatting (CI uses this)
task deps-start # Docker Compose up (Kafka, RabbitMQ, MySQL, etc.)
task deps-stop # Docker Compose down
task example-service # Run example service
task example-client # Run example client
task validate # Validate Taskfile.yml
task --list # List all available tasks- Single test:
go test ./path/to/pkg -run ^TestName$ -v -race. Integration: add-tags=integration. - Test files:
*_test.go(unit),*_integration_test.go(integration with//go:build integration). - goleak in
TestMainfor goroutine leak detection; testifyassert/requirefor assertions. - CI:
.github/workflows/ci.yml— validates Taskfile, lint, format check, integration tests (excludesexamplesandencoding/protobuf/test), e2e example tests. Codecov enabled. - Prerequisites: golangci-lint v2.6.1. Install:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v2.6.1. - Git worktrees:
wt <branch-name>for parallel development.
.golangci.yml: errcheck, errorlint, revive, staticcheck, govet, gosec, sqlclosecheck, rowserrcheck, exhaustive, prealloc, whitespace, sloglint, spancheck, testifylint, and more. Build tagintegration; vendor mode; tests linted. Formatters: gofmt, gofumpt, goimports.
- Imports: standard → third-party → module-local (goimports manages).
- Naming: PascalCase exported (with doc comments), lowerCamelCase unexported,
-erinterfaces, no stutter. - Errors: sentinel or wrapped (
%w);errors.Joinfor aggregation;errors.Is/Asfor comparison; never panic in library code; never swallow errors. - Context:
context.Contextas first param for blocking/request-scoped calls. - Concurrency: contexts + timeouts; no goroutine leaks; close resources; guard shared state;
-raceenforced. - Functional options:
OptionFuncpattern for all constructors —New(required, opts...).
- Never panic in library code — return errors.
- Never use global mutable state — pass via context or constructor.
- Never swallow errors — errcheck linter enforced.
- Never skip
context.Contextas first param in blocking calls. - Never leave goroutines unmanaged — goleak in TestMain catches leaks.
- Never use builder pattern — replaced by functional options in v0.74.0.
| Variable | Purpose | Default |
|---|---|---|
PATRON_HTTP_DEFAULT_PORT |
HTTP server port | 50000 |
PATRON_HTTP_READ_TIMEOUT |
HTTP read timeout | — |
PATRON_HTTP_WRITE_TIMEOUT |
HTTP write timeout | — |
PATRON_HTTP_STATUS_ERROR_LOGGING |
Enable HTTP error logging | — |
PATRON_LOG_LEVEL |
Log level (debug/info/warn/error) | — |
OTEL_EXPORTER_OTLP_INSECURE |
Insecure OTLP exporter | false |
- Issues:
.github/ISSUE_TEMPLATE.md. PRs:.github/PULL_REQUEST_TEMPLATE.md. - Sign commits (
SIGNYOURWORK.md); high test coverage; lint-clean; CI must pass. - Breaking changes: document in
BREAKING.mdwith migration guide. - OTel upgrades: update
semconvimport path to matching version;go mod tidy && go mod vendor.
| Path | AGENTS.md | Focus |
|---|---|---|
component/http/ |
✅ | Routes, middleware, cache, auth, router |
client/ |
✅ | Client conventions, options, instrumentation |
observability/ |
✅ | OTel setup, logging, tracing, metrics |
cache/ |
✅ | Cache interfaces, LRU, Redis |
reliability/ |
✅ | Circuit breaker, retry |
You have context-mode MCP tools available. These rules are NOT optional — they protect your context window from flooding. A single unrouted command can dump 56 KB into context and waste the entire session.
Any shell command containing curl or wget will be intercepted and blocked by the context-mode plugin. Do NOT retry.
Instead use:
context-mode_ctx_fetch_and_index(url, source)to fetch and index web pagescontext-mode_ctx_execute(language: "javascript", code: "const r = await fetch(...)")to run HTTP calls in sandbox
Any shell command containing fetch('http, requests.get(, requests.post(, http.get(, or http.request( will be intercepted and blocked. Do NOT retry with shell.
Instead use:
context-mode_ctx_execute(language, code)to run HTTP calls in sandbox — only stdout enters context
Do NOT use any direct URL fetching tool. Use the sandbox equivalent. Instead use:
context-mode_ctx_fetch_and_index(url, source)thencontext-mode_ctx_search(queries)to query the indexed content
Shell is ONLY for: git, mkdir, rm, mv, cd, ls, npm install, pip install, and other short-output commands.
For everything else, use:
context-mode_ctx_batch_execute(commands, queries)— run multiple commands + search in ONE callcontext-mode_ctx_execute(language: "shell", code: "...")— run in sandbox, only stdout enters context
If you are reading a file to edit it → reading is correct (edit needs content in context).
If you are reading to analyze, explore, or summarize → use context-mode_ctx_execute_file(path, language, code) instead. Only your printed summary enters context.
Search results can flood context. Use context-mode_ctx_execute(language: "shell", code: "grep ...") to run searches in sandbox. Only your printed summary enters context.
- GATHER:
context-mode_ctx_batch_execute(commands, queries)— Primary tool. Runs all commands, auto-indexes output, returns search results. ONE call replaces 30+ individual calls. - FOLLOW-UP:
context-mode_ctx_search(queries: ["q1", "q2", ...])— Query indexed content. Pass ALL questions as array in ONE call. - PROCESSING:
context-mode_ctx_execute(language, code)|context-mode_ctx_execute_file(path, language, code)— Sandbox execution. Only stdout enters context. - WEB:
context-mode_ctx_fetch_and_index(url, source)thencontext-mode_ctx_search(queries)— Fetch, chunk, index, query. Raw HTML never enters context. - INDEX:
context-mode_ctx_index(content, source)— Store content in FTS5 knowledge base for later search.
- Keep responses under 500 words.
- Write artifacts (code, configs, PRDs) to FILES — never return them as inline text. Return only: file path + 1-line description.
- When indexing content, use descriptive source labels so others can
search(source: "label")later.
| Command | Action |
|---|---|
ctx stats |
Call the stats MCP tool and display the full output verbatim |
ctx doctor |
Call the doctor MCP tool, run the returned shell command, display as checklist |
ctx upgrade |
Call the upgrade MCP tool, run the returned shell command, display as checklist |