Cursor rules for Go
Standard Go toolchain, errors with context, generated code left alone.
.cursor/rules/go.mdc
--- description: Conventions and guardrails for the Go codebase globs: **/*.go alwaysApply: false --- # Go service ```bash go build ./... # compile everything go test ./... # run the tests go test -race ./... # run the tests with the race detector go vet ./... # static checks ``` Run the tests after every code change. - Return errors, wrapped with context using fmt.Errorf and %w. Do not panic outside of main and init. - Pass context.Context as the first argument to anything that does I/O, and respect cancellation. - Run gofmt on every file you change. No new dependencies without asking. Rules for every edit: - Never read, print, edit or commit .env files, credentials, API keys or private keys. - Database schema changes go through migration files in the repo. Never edit a migration that has shipped; add a new one. - Never deploy to production. I run production deploys myself. - Never run git push --force, git reset --hard, git clean, git checkout -- <file>, git stash or git rebase, and never use --no-verify. Ask first. - go.sum: never edit by hand. Do not change go.mod or add dependencies without asking.
Why it says what it says
Standard toolchain commands
Go has a small, stable set of commands. Listing them, including the race detector, gives the agent a complete self-check.
Errors and context
Swallowed errors and missing context propagation are the usual agent mistakes in Go. Two short rules cover them.
Generated files
Hand edits to generated code are overwritten on the next run. Pointing at the source avoids lost work.
go.mod and go.sum
Dependency changes ripple through the build. They need a human decision.
Deploys and migrations
Both are hard to undo, so the rules keep the agent on the safe side of each.