go-guidelines

A set of coding rules for Go, a programming language often used for backend services and command-line tools. The rules cover formatting, naming, errors, interfaces, context, and dependency injection.

In plain words
What is it for?
Use it when writing or reviewing Go packages, services, error handling, interfaces, request-scoped operations, and dependency setup.
Why use it?
It makes expectations for Go code explicit, helping teams produce consistent code and avoid ignored errors or unclear dependencies.

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/showcase-gig-platform/cursor-rules-initializer/go-guidelines
Clone the repo
git clone --depth 1 https://github.com/showcase-gig-platform/cursor-rules-initializer

Made for: Cursor.

Per session 991 This file is loaded in full into every session.
When invoked 991 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.00991 $0.00991
Opus 5 $0.00495 $0.00495
Sonnet 5 $0.00198 $0.00198
Haiku 4.5 $0.00099 $0.00099

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

Security

Grade A, and why

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

.cursor/commands/cursor-rules-initializer/sample/rules/base/go-guidelines.mdc · 49 lines

What it actually says

Go コーディングガイドライン

Go のコーディング規則

  • フォーマット: make lint を実行し、goimports によるフォーマットと go vet による静的解析をパスすること。golangci-lint もCIで実行される。
  • 命名規則:
    • パッケージ名: lowercase または snake_case (例: user, order_repository)
    • 型名 (struct, interface): PascalCase
    • 変数名: camelCase (スコープに応じて説明的な長さに)
    • 関数・メソッド名: 公開は PascalCase, 非公開/メソッドは camelCase。動詞で始める。
    • 定数名: PascalCase。関連する定数は接頭辞でグループ化 (例: OrderStatePending, OrderStateCompleted)。
    • エラー変数: 公開は ErrXxx (例: ErrOrderNotFound), 非公開は errXxx
    • ファイル名: snake_case.go (例: order_entity.go, user_service.go)
  • エラーハンドリング:
    • エラーは適切にチェックし、無視しない。
    • エラーをラップする場合は fmt.Errorf%w を使用し、コンテキストを追加する。
    • Sentinel Error (ErrXxx 形式の公開エラー変数) またはカスタムエラー型を適切に使い分ける。
    • ユースケース層でのエラーは app/usecase/error.go で定義されたエラー型を使用することを検討する。
  • インターフェース:
    • 利用側で定義する (Consumer-defined interfaces)。
    • 必要最小限のメソッドを持つように設計する (if needed ベース)。
    • インターフェース名は能力を表すようにする (例: OrderReader, PaymentProcessor)。
  • Context:
    • リクエストスコープの処理やキャンセル伝播のために context.Context を第一引数として渡す。
    • Contextからの値の取得は context.Value を直接使うのではなく、型安全なヘルパー関数を用意する。
  • 依存性注入: DIコンテナやwireなどのツールを使用して依存関係を管理する。
  • ゼロ値: 構造体のフィールドは可能な限りゼロ値が意味を持つように設計する。ポインタ型は nil が有効な状態を表す場合にのみ使用する。
  • 並行処理:
    • Goroutineを使用する場合は、リソースリークやレースコンディションに注意する。
    • sync パッケージ (Mutex, WaitGroupなど) を適切に使用する。
    • Channelを使ったコミュニケーションを検討する。
  • コメント:
    • 公開される型、関数、定数、変数には godoc コメントを記述する。
    • 複雑なロジックや、自明でないコードには説明コメントを追加する。
    • TODOコメントには担当者やIssue番号を含めることが望ましい。
  • テスト: test-rule.mdc の規則に従う。

エラーハンドリングとロギング

  • エラーの種類に応じて適切なログレベルを使用する:
    • Info: 通常の操作情報
    • Warn: 警告(重大ではないが注意が必要)
    • Error: 重大なエラー(サービスの一部機能に影響)
    • Fatal: 致命的なエラー(サービス全体に影響)
  • ユーザーに表示するエラーメッセージと内部ログは分離する。
  • 外部サービス連携時のエラーは適切にラップし、必要に応じてリトライロジックを実装する。
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 · 991 tokens per session scan A 986075df7aa1

Subscribe to this mod's changes

go-guidelines is a cursor rule published in the GitHub repository showcase-gig-platform/cursor-rules-initializer (7 stars, last pushed 9mo ago), licensed MIT. It adds 991 tokens to every session, about $0.0050 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.