CursorGoCode Style

Go Cursor Rules

Cursor rules for Go: idiomatic Go patterns, error handling, concurrency, and Go module conventions.

.cursorrules
- Always handle errors explicitly; never use blank identifier _ for errors
- Return errors as the last return value; wrap with fmt.Errorf("context: %w", err)
- Use sentinel errors (var ErrNotFound = errors.New(...)) for expected error types
- Keep interfaces small; prefer single-method interfaces (io.Reader, io.Writer)
- Use context.Context as the first parameter of all functions doing I/O
- Avoid goroutine leaks: always have an exit condition for goroutines
- Use table-driven tests with t.Run for organized test cases
- Run gofmt, golangci-lint, and go vet in CI

How to use with Cursor

Create a `.cursorrules` file in your project root and paste these rules. Cursor reads this automatically on every AI interaction.

#go#golang#errors#concurrency#cursor#coding-rules

Related Rules