Home › All rules › Community › Go Cursor Rules

Go Cursor Rules

Idiomatic Go rules. Explicit error handling, interface-based design, context-first concurrency.

CursorGoCommunity (CC0)

How to use

Save this as .cursor/rules/go.mdc in your project, commit it, and Cursor will load it. Review it first: community files can be opinionated or out of date.

Note: Review and test before use. Provided as is, without warranty. See Terms.

.cursor/rules/go.mdcDownload  
---
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

More: Go rules · all community rules

Related rules

Go backend CLAUDE.md

CLAUDE.md for idiomatic Go HTTP services using the standard library, sqlc and table-driven tests.

Claude Code (CLAUDE.md)Go

Go CLI (Cobra) CLAUDE.md

CLAUDE.md for command-line tools in Go 1.27 with Cobra: commands, flags, output formats, exit codes, and tests.

Claude Code (CLAUDE.md)Go

Go concurrency Windsurf rules

Windsurf rules for safe Go concurrency: goroutine lifetimes, context cancellation, errgroup, channels, and the race detector.

WindsurfGo

Go Backend Scalability Cursor Rules

Cursor rules for Go development with backend scalability.

CursorGoCommunity (CC0)

Go Servemux Rest Api Cursor Rules

Cursor rules for Go development with ServeMux REST API integration.

CursorGoCommunity (CC0)

Google Adk Cursor Rules

Google Agent Development Kit rules for agents, tools, sessions, memory, artifacts, evaluation, and deployment

CursorGoCommunity (CC0)

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.