4 go rules available
Cursor has four Go rules: a substantive backend development rule plus short rules on interface design, concurrency and testing. As an .mdc rule with globs, the file below attaches only when Go files are in the request, which matters in monorepos with a TypeScript frontend.
Cursor applies project rules stored as .mdc files in .cursor/rules. Each rule's frontmatter (description, globs, alwaysApply) decides whether it is always included, attached to matching files, chosen by the agent from its description, or only used when you @-mention it. Cursor also reads AGENTS.md in the project root and subdirectories for plain-Markdown instructions.
.cursor/rules/go.mdcStarting point, not a tested configuration for your repository. Attached when files matching the globs are in context (alwaysApply: false with globs). Review the instructions, adapt the file paths and run your project's existing checks.
---
description: "Go development project conventions"
globs: "**/*.go"
alwaysApply: false
---
# Go instructions for Cursor
## Focus for this project
- Define small interfaces in the consuming package, not next to the implementation.
- Bound concurrency with a worker pool or errgroup.SetLimit; every goroutine must have a clear exit on context cancellation.
- Never share a map between goroutines without a mutex; prefer passing values over channels.
## Go conventions
- Read the go directive in go.mod before using newer standard-library APIs. With go 1.22 or later, register routes with method and wildcard patterns such as mux.HandleFunc("GET /users/{id}", h) and read the value with r.PathValue("id"); on older modules keep the router the project already uses.
- Pass context.Context as the first parameter of any function that does I/O, and stop work when ctx.Done() closes.
- Wrap errors with fmt.Errorf("...: %w", err) and compare with errors.Is or errors.As; never compare error strings.
- Write table-driven tests with t.Run subtests next to the code (foo_test.go).
## Before you finish
- Run gofmt -l . (must print nothing), go vet ./... and go test -race ./... and report the actual output. If you cannot run them, say so and list the exact commands instead of saying they pass.
- Summarize which of the rules above affected the change.
- If another attached Cursor rule conflicts with this one, name both rules and follow the one with the narrower globs.
Create your own Cursor rules for Go and share with the community.
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
Cursor's docs recommend keeping individual rules under 500 lines and splitting large rules into composable ones. Cursor's documentation states that it supports AGENTS.md in the project root and in subdirectories. Use AGENTS.md for plain-Markdown instructions you also want other tools to read, and .mdc rules when you need Cursor's scoping options (globs, description-based selection, always-apply).
Documentation checked 2026-11-05: Cursor docs: Rules
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
You ask Cursor's agent to add a worker that processes jobs concurrently and want bounded concurrency, cancellation and race-free tests.
Add a function that fetches 500 URLs with at most 10 in flight and stops on the first error.
An errgroup.WithContext with SetLimit(10) (or a worker pool), requests built with the group context, the first error returned, and a test run with -race.
Content reviewed 2026-11-05. Confirm instruction activation in your installed client before relying on it.
Cursor rules for Go interfaces that stay small, live with their consumers, compose, are checked at compile time and have documented contracts and simple fakes.