cursorrules

A set of Cursor editor rules for writing Go programs. Cursor is a code editor with AI features, and Go is a programming language.

In plain words
What is it for?
Use it when generating or reviewing Go code, especially code that needs gofmt or goimports formatting, go vet or golangci-lint checks, explicit errors, and small focused interfaces.
Why use it?
It gives the agent consistent expectations for formatting, package design, imports, error handling, interfaces, and code-quality checks. This reduces style drift and common Go mistakes.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/lay4u/awesome-ai-rules/cursorrules
Clone the repo
git clone --depth 1 https://github.com/Lay4U/awesome-ai-rules

Made for: Cursor.

Per session 466 This file is loaded in full into every session.
When invoked 466 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00466 $0.00466
Opus 5 $0.00233 $0.00233
Sonnet 5 $0.00093 $0.00093
Haiku 4.5 $0.00047 $0.00047

Measured 2d ago against content hash 1e53d9a50f51, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

cursorrules scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/cursor/go/.cursorrules · 48 lines

How it starts

The opening of the file, as written. The whole thing — 48 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Cursor Go Rules

IDE-First Defaults

  • Always format on save with gofmt (or goimports when available).
  • Never accept code that is unformatted; formatting is non-negotiable.
  • Organize imports automatically; avoid manual import micromanagement.
  • Keep editor diagnostics on for go vet and golangci-lint.

Go Code Style

  • Prefer small packages with focused responsibilities.
  • Package names must be short, lowercase, and without underscores.
  • Prefer composition over inheritance-style embedding chains.
  • Avoid init(); use explicit constructors and setup functions.
  • Keep exported APIs minimal and stable.

Error Handling

  • Use explicit error returns; Go has no exceptions for normal control flow.
  • Return early on errors and keep happy-path unindented.
  • Wrap errors with %w when adding context.
  • Compare with errors.Is/errors.As instead of string matching.
  • Do not swallow errors; either handle, wrap, or return them.

Interfaces and API Design

  • Prefer small interfaces (1-3 methods) near the consuming package.
  • Accept interfaces in function parameters when behavior is needed.
  • Return concrete structs from constructors for better discoverability.
  • Avoid exporting interfaces prematurely.

Concurrency and Context

  • Pass context.Context as the first parameter for request-scoped work.
  • Never store context.Context inside structs.
  • Use goroutines only with a clear lifecycle and cancellation path.
  • Prefer channels for coordination, not as a replacement for all state.
  • Close channels only from the sender side.
  • Guard shared mutable state with sync.Mutex/sync.RWMutex.

Testing in the Editor Loop

  • Use table-driven tests for branch-heavy logic.
  • Run go test ./... before finalizing changes.
  • Use testify/require for must-stop assertions and assert for continued checks.
  • Keep tests deterministic; avoid sleeps when synchronization primitives are possible.
  • Add race checks (go test -race ./...) when touching concurrency.

Modules and Dependencies

  • Use Go modules and keep go.mod/go.sum in sync.
  • Prefer standard library packages before adding new dependencies.
  • Add dependencies deliberately; remove unused ones promptly.

Read the full file on GitHub · 48 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 48 lines · 466 tokens per session scan A 1e53d9a50f51

Subscribe to this mod's changes

cursorrules is a cursor rule published in the GitHub repository Lay4U/awesome-ai-rules (5 stars, last pushed 6mo ago), licensed MIT. It adds 466 tokens to every session, about $0.0023 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.