pn-go-backend

pn-go-backend is a cursor rule for Cursor from perniemann/pnCore. It costs 0 tokens per session (740 once invoked), scanned A, original, MIT.

A set of style and safety rules for Go backend programs, including APIs and servers built with Gin, Fiber, or Echo. Go is a programming language often used for server software.

In plain words
What is it for?
Use it when writing or changing Go API handlers, server logic, database or network calls, configuration, and error handling.
Why use it?
It reduces lost errors, missing request cancellation, unclear logs, and inconsistent naming in code that handles network requests and other input/output.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc). Also seen: positional $N argument.

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/perniemann/pncore/pn-go-backend
Clone the repo
git clone --depth 1 https://github.com/perniemann/pnCore

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for pn-go-backend

README.md
[![agentmods](https://agentmods.dev/badge/rules/perniemann/pncore/pn-go-backend.svg)](https://agentmods.dev/rules/perniemann/pncore/pn-go-backend)
Your own site
<a href="https://agentmods.dev/rules/perniemann/pncore/pn-go-backend"><img src="https://agentmods.dev/badge/rules/perniemann/pncore/pn-go-backend.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 740 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.1 $0.00000 $0.00740
Opus 5 $0.00000 $0.00370
Sonnet 5 $0.00000 $0.00148
Haiku 4.5 $0.00000 $0.00074

Measured 5d ago against content hash ceca5314c7f8, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

pn-go-backend 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 5d 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.

packages/pn-core-mcp/content/rules/pn-go-backend.mdc · 47 lines

How it starts

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

Go / backend rules

Error handling

  • Check every returned error. Never discard with _ unless you have an explicit written reason.
  • Wrap errors with context using fmt.Errorf("operation failed: %w", err). Use errors.Is and errors.As for comparison — never string-match error messages.
  • Define sentinel errors for expected failures: var ErrNotFound = errors.New("not found"). Return these for known operational states.
  • Use log/slog (Go 1.21+) for structured logging. Log errors at the level where recovery is decided, not at every call site.

Context

  • Pass context.Context as the first parameter in all I/O functions: func FetchUser(ctx context.Context, id int64) (*User, error).
  • Respect context cancellation: check ctx.Err() in loops and before expensive operations.
  • Never store context in structs. Never use context.Background() inside a request handler — propagate the request context.

Naming and style

  • Use short variable names in small scopes (i, v, err) but descriptive names for exported types and functions.
  • Exported names are PascalCase; unexported are camelCase. Acronyms follow Go convention: userID, httpClient, parseURL.
  • Interfaces belong in the package that uses them, not the package that implements them.
  • Avoid init() for side effects. Initialize dependencies explicitly in main or constructors.

Secrets and config

  • All config and secrets from environment variables (os.Getenv). Never hardcode secrets in source.
  • Use os.LookupEnv when a missing variable must be detected: val, ok := os.LookupEnv("DB_URL"); if !ok { log.Fatal("DB_URL required") }.
  • Consider envconfig or viper for structured config with validation at startup.

Goroutines and concurrency

  • Every goroutine must have an owner responsible for its lifetime. Use sync.WaitGroup, errgroup, or channel signaling.
  • Avoid goroutine leaks: goroutines that block on channels or I/O indefinitely. Use context.WithTimeout for all external calls.
  • Prefer errgroup.Group over raw goroutines for parallel work that must be joined and checked for errors.

Read the full file on GitHub · 47 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. 5d ago First seen · 47 lines · 0 tokens per session scan A ceca5314c7f8

Subscribe to this mod's changes

pn-go-backend is a cursor rule published in the GitHub repository perniemann/pnCore (0 stars, last pushed 2d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 740 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-31.