go · patrickjs — Cursor rule: what it does, how to install
This rule guides Cursor toward idiomatic Go with explicit errors, interface-based design, and context-aware concurrency. It targets .go files.
.cursor/rules/go.mdcWhat go does
This rule steers Cursor toward clear Go practices. It asks the agent to handle every error, wrap failures with fmt.Errorf("context: %w", err), inspect them through errors.Is() and errors.As(), and use custom error types when an error needs structure.
It also sets naming guidance for short-lived variables and acronyms, while keeping interfaces small and ending them with -er. Functions should accept interfaces and return concrete types. Blocking functions take context.Context first; goroutine groups use WaitGroup, channels carry communication, and mutexes protect shared state. Tests use table-driven cases and interface-based mocks.
The rule rejects ignored errors, business logic in init(), mutable global state, and goroutines without a termination condition. Its scope is **/*.go, so files outside that pattern are not covered.
What it helps with
- handle Go errors instead of assigning them to
_ - design small interfaces at the call site
- pass
context.Contextto blocking functions - write table-driven tests with
t.Run - give goroutines an explicit termination condition
Example prompts for the agent
- Review this Go code and fix its error handling under the rule.
- Rewrite this concurrent function so
context.Contextis its first parameter. - Add table-driven tests with
t.Runand interface-based mocks.
How to install go
Manually: put the files in place
.cursor/rules/go.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.claude/rules/go.mdThe paths frontmatter field limits the files: move globs from the source into paths
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.github/instructions/go.instructions.mdThe applyTo field sets which files it applies to: move globs from the source into applyTo
Manually: put the files in place
.devin/rules/go.mdManually: put the files in place
.clinerules/go.mdStep by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules
Questions about go
How do I install go in Cursor?
Create .cursor/rules/go.mdc and place the rule content in that file.
What does the go rule do?
It guides Go error handling, naming, interface design, concurrency, and testing.
Which files does go apply to?
Its glob is **/*.go, so the rule covers Go files matching that pattern.
Source text
go.mdc · CC0-1.0
---
description: "Idiomatic Go rules. Explicit error handling, interface-based design, context-first concurrency."
globs: **/*.go
alwaysApply: false
---
# Go Language Rules
Expert Go developer. Simple, explicit, idiomatic.
## Error Handling
- Always handle errors — never assign to _
- fmt.Errorf("context: %w", err) for wrapping
- errors.Is() / errors.As() for checking
- Custom error types for structured errors
## Naming
- Short for short-lived vars: i, n, err, ok
- No stuttering: user.UserID → user.ID
- Acronyms: userID, httpClient (not userId, httpClient)
- Interfaces: end in -er (Reader, Writer, Handler)
## Interfaces
- Accept interfaces, return concrete types
- Define at call site, not implementation site
- Single-method interfaces preferred
## Concurrency
- context.Context first param for blocking functions
- defer cancel() after context creation
- WaitGroup for goroutine groups
- Channels for communication, Mutex for state
## Testing
- Table-driven: for _, tc := range testCases { t.Run(tc.name, ...) }
- Interface-based mocking
## Forbidden
- No _ to ignore errors
- No init() for business logic
- No global mutable state
- No interface{} where generics work
- No goroutines without termination condition
© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules
Similar IDE rules
All IDE rules for Programming languages →go by other authors comes first.