with one click
writing-go-code
// Use when writing, modifying, or reviewing .go files, implementing new Go functions or packages, or when Go code style and conventions are relevant.
// Use when writing, modifying, or reviewing .go files, implementing new Go functions or packages, or when Go code style and conventions are relevant.
Use when creating, modifying, or reviewing E2E tests in pkg/e2e/tests/. Triggers on "e2e test", "add e2e test", "new e2e test", or when working with files under pkg/e2e/tests/.
Use when creating branches, committing changes, pushing, or opening pull requests. Triggers on "make a PR", "open a PR", "create a branch", "push this", "commit and push", or any request to ship code to GitHub.
Creates and modifies PostgreSQL database migrations for xmtpd using golang-migrate. Use when adding or altering tables, columns, indexes, functions, triggers, constraints, or partitions, or when the user mentions migrations or schema changes.
Writes and modifies sqlc queries for the xmtpd PostgreSQL database. Use when creating, editing, or reviewing .sql query files in pkg/db/sqlc/, when the user mentions sqlc, database queries, or adding new database operations.
| name | writing-go-code |
| description | Use when writing, modifying, or reviewing .go files, implementing new Go functions or packages, or when Go code style and conventions are relevant. |
golangci-lint fmtMaxLength not MAX_LENGTH)PascalCasecamelCaseHTTPClient, xmlParserutil/common/basequeue.New() not queue.NewQueue()init() unless absolutely necessaryTestXxx, BenchmarkXxxt.Helper() in helper functionst.Context() rather than context.Background() or context.TODO()After every change to .go files:
dev/lint-fix — runs golangci-lint with --fix to auto-format and fix lint issuesgolangci-lint run passes with 0 issuesBoth must pass before the task is considered done. dev/lint-fix covers gofmt, gofumpt, golines, and all enabled linters.
All metrics live in pkg/metrics/. The project uses Prometheus via github.com/prometheus/client_golang.
api.go — API-layer metrics (connections, envelope rates, latency)sync.go — node-to-node replication metricsblockchain.go — chain interaction metricsindexer.go, payer.go, dbmetrics.go, migrator.go — domain-specificregisterCollectors() in metrics.goEmit* function in the same filedev/gen/metrics-catalog| Use case | Type |
|---|---|
| Count of events (requests, envelopes, errors) | Counter — monotonically increasing, use _total suffix |
| Current state (open connections, queue depth) | Gauge — can go up and down |
| Duration / latency distribution | Histogram — use _seconds suffix, observe in seconds |
xmtp_<subsystem>_<name>_<type-suffix>xmtp_api_outgoing_envelopes_total, xmtp_sync_messages_received_count_total or _counter_seconds, _duration_gauge or none// Counter — simple increment
func EmitFoo() { fooTotal.Inc() }
// Counter — batch add
func EmitFoos(n int) { fooTotal.Add(float64(n)) }
// Histogram — observe duration
func EmitFooDuration(d time.Duration) { fooDuration.Observe(d.Seconds()) }
// Gauge with labels — use With()
func EmitBarGauge(label string, v float64) {
barGauge.With(prometheus.Labels{"label": label}).Set(v)
}
metrics.goEmit* function exported from pkg/metricsdev/gen/metrics-catalog run to update doc/metrics_catalog.mdSee these references for detailed guidance on frequent Go mistakes: