Skip to main content
rule

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.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/go.mdc
Open on GitHub

What 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.Context to 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.Context is its first parameter.
  • Add table-driven tests with t.Run and interface-based mocks.

How to install go

Manually: put the files in place

.cursor/rules/go.mdc

Frontmatter: description, globs, alwaysApply

Step 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.

From the same set210

hol-hedera-typescript-cursorrules-prompt-file Cursor rules for building decentralized Hedera AI agents with Hashgraph Online SDK in TypeScript. Enforces strict typing and TDD workflow. ★ 41,024repo stars harmony-arkts A Cursor rule for HarmonyOS ArkTS code covering components, state, resources, layout, lifecycle, and accessibility. Useful for .ets projects. ★ 41,024repo stars graphical-apps-development-cursorrules-prompt-file A Cursor rule that feeds the agent the Pyllments context: graph-based LLM apps in Python built on Panel and Langchain. ★ 41,024repo stars google-adk Guides Cursor when building agents with the Google Agent Development Kit. It enforces patterns for tools, session memory, artifacts, and multi-agent systems. ★ 41,024repo stars go-servemux-rest-api-cursorrules-prompt-file A Cursor rule that points the assistant at Go REST APIs built with net/http and the ServeMux router from Go 1.22. ★ 41,024repo stars go-backend-scalability-cursorrules-prompt-file Shapes Cursor responses for scalable Go backends by enforcing planning steps, architectural trade-offs, and final summaries. ★ 41,024repo stars github-cursorrules-prompt-file-instructions This Cursor rule guides code work toward readable, maintainable code with clear names, focused functions, and useful comments. ★ 41,024repo stars github-code-quality-cursorrules-prompt-file A set of guardrails for the Cursor agent: check facts before asserting them, skip apologies and recaps, change one file at a time. ★ 41,024repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor