go-idiomatic-code

A set of rules for writing Go code in the style commonly expected by the Go community.

In plain words
What is it for?
It guides names, imports, code layout, function size, receiver methods, and checking errors when creating or reviewing Go code.
Why use it?
It reduces inconsistent naming, organization, and error handling that can make Go code harder to read and maintain.

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/dstotijn/go-mcp/go-idiomatic-code
Clone the repo
git clone --depth 1 https://github.com/dstotijn/go-mcp

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 879 The whole file, excluding the scripts and references it only reads on demand.
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.00000 $0.00879
Opus 5 $0.00000 $0.00439
Sonnet 5 $0.00000 $0.00176
Haiku 4.5 $0.00000 $0.00088

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

Security

Grade A, and why

go-idiomatic-code 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

2 near-identical copies found in the catalogue:

.cursor/rules/go-idiomatic-code.mdc · 107 lines

How it starts

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

Description

This rule ensures that all Go code follows idiomatic Go practices, adhering to the official Go style guide and common best practices in the Go community.

Rule

When writing Go code:

Naming Conventions

  1. Use camelCase for variable and function names (not snake_case)
  2. Use PascalCase for exported names (public functions, types, variables, constants)
  3. Use camelCase for unexported names (private functions, types, variables, constants)
  4. Use acronyms in all caps (e.g., HTTP, URL, ID) when they appear at the beginning of a name, otherwise all lowercase
  5. Keep names short and descriptive; the larger the scope, the more descriptive the name should be

Code Organization

  1. Group related declarations (imports, constants, types, variables, functions)
  2. Order imports in groups: standard library, third-party packages, local packages
  3. Use blank lines to separate logical sections of code
  4. Keep functions small and focused on a single responsibility
  5. Place methods on receiver types in a logical order, with the most important methods first

Error Handling

  1. Always check errors and handle them appropriately
  2. Use the errors package for simple errors and fmt.Errorf with %w for wrapping errors
  3. Return errors rather than using panic (except for truly unrecoverable situations)
  4. Use meaningful error messages that help diagnose the problem

Comments and Documentation

  1. Write comments as complete sentences with proper punctuation (ending with a period)
  2. Use godoc-style comments for exported functions, types, and variables
  3. Focus on explaining "why" rather than "what" in comments
  4. Document non-obvious behavior and edge cases

Code Style

  1. Use gofmt/goimports to format code
  2. Avoid unnecessary else blocks after return statements
  3. Prefer early returns to reduce nesting
  4. Use named return values only when they improve readability
  5. Limit line length to 100-120 characters
  6. Use blank interfaces (any) sparingly
  7. Use any instead of interface{}

Read the full file on GitHub · 107 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 · 107 lines · 879 tokens per session scan A dfebda9ec361

Subscribe to this mod's changes

go-idiomatic-code is a cursor rule published in the GitHub repository dstotijn/go-mcp (18 stars, last pushed 1y ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 879 tokens. 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.