go

A set of coding rules for Go, the programming language, covering naming, formatting, error handling, interfaces, and goroutines, which are Go's lightweight concurrent tasks.

In plain words
What is it for?
Reviewing or writing Go code, applying standard naming and formatting, wrapping errors, defining interfaces, and working with concurrent goroutines.
Why use it?
It keeps Go code consistent and encourages errors to be handled with enough context to diagnose them.

Cursor rule

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/nedcodes-ok/cursorrules-collection/go
Clone the repo
git clone --depth 1 https://github.com/nedcodes-ok/cursorrules-collection
Per session 1,028 This file is loaded in full into every session.
When invoked 1,028 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.01028 $0.01028
Opus 5 $0.00514 $0.00514
Sonnet 5 $0.00206 $0.00206
Haiku 4.5 $0.00103 $0.00103

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

Security

Grade A, and why

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

Origin

Copies of this mod

1 near-identical copy found in the catalogue:

  • go — 100% identical, 0 lines differ
rules-mdc/languages/go.mdc · 49 lines

How it starts

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

Go Cursor Rules

You are an expert Go developer (1.21+). Follow these rules:

Code Style

  • gofmt / goimports formatting is mandatory — no style debates, the formatter decides
  • Short but descriptive names: userID not theUserIdentifier. Receiver names are 1-2 letters (s for server, u for user). Don't name receivers self or this
  • MixedCaps only, never underscores in Go names. Exported = Uppercase, unexported = lowercase — this is access control, not convention
  • Package names are lowercase, single word, no underscores: httputil not http_util. The package name is part of the call site: httputil.NewClient not httputil.NewHTTPUtilClient

Error Handling

  • Check every error immediately. Never discard with _ unless you comment why: _ = conn.Close() // best-effort cleanup
  • Wrap errors with context: fmt.Errorf("fetching user %d: %w", id, err)%w wraps (unwrappable), %v formats (not unwrappable). Always use %w when the caller might need to inspect the cause
  • Sentinel errors (var ErrNotFound = errors.New("not found")) for expected conditions callers handle differently. Custom error types (type ValidationError struct{}) when the error carries structured data
  • errors.Is() for sentinel comparison, errors.As() for type extraction — never err.Error() == "some string", error messages are not API
  • Don't log and return the same error — pick one. Logging + returning means the error gets logged at every level of the call stack

Concurrency

  • Every goroutine must have a clear shutdown path — context.Context for cancellation, done channels for signaling
  • Creator of a channel closes it. Never close from the receiver side — it panics if multiple goroutines receive
  • sync.WaitGroup for fan-out when all goroutines must complete. errgroup.Group when you need the first error and want to cancel the rest
  • sync.Mutex for protecting shared state. Channels for communication between goroutines. Don't use channels as mutexes — it's clever but unreadable
  • Watch for goroutine leaks: a goroutine blocked on a channel send/receive with no timeout lives forever. Always pass a context with timeout or deadline
  • sync.Once for one-time initialization (DB connection, config load) — not init() which runs at import time and is hard to test

Read the full file on GitHub · 49 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 · 49 lines · 1,028 tokens per session scan A b1956f3e5e17

Subscribe to this mod's changes

go is a cursor rule published in the GitHub repository nedcodes-ok/cursorrules-collection (37 stars, last pushed 6mo ago), licensed MIT. It adds 1,028 tokens to every session, about $0.0051 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-30.