cursor-rule-template

A Cursor rule template for gospec, a set of software-development rules for Go backends. It routes different tasks to the relevant architecture, API, data, security, testing, and migration guidance.

In plain words
What is it for?
Use it in Cursor when developing Go services, handlers, business logic, database access, Redis features, authentication, concurrency, migrations, observability, tests, or design documents.
Why use it?
Backend work can violate project boundaries or conventions when the relevant rules are hard to find. This template provides a single entry point and identifies which guidance to consult for each task.

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/singchia/gospec/cursor-rule-template
Clone the repo
git clone --depth 1 https://github.com/singchia/gospec
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,234 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.01234
Opus 5 $0.00000 $0.00617
Sonnet 5 $0.00000 $0.00247
Haiku 4.5 $0.00000 $0.00123

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

Security

Grade A, and why

cursor-rule-template 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.

docs/templates/cursor-rule-template.mdc · 95 lines

How it starts

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

gospec —— Go 后端 SDLC 规范(Cursor 单文件入口)

本文件由 gospec 自动生成,作为 Cursor 的唯一入口。 完整规范在 ~/.claude/skills/gospec/spec/.claude/skills/gospec/spec/。 Cursor 已通过 globs 自动附加,无需用户每次选择。

任务路由(先看这个表,再决定要不要展开 spec/)

任务 最少必读
写 HTTP / gRPC handler(service/ spec/03-api/proto.md + spec/03-api/http.md + spec/05-coding/errors.md
写业务用例(biz/ spec/02-architecture/layering.md + spec/05-coding/errors.md
写 goroutine / 用锁 / 传 context spec/05-coding/concurrency.md
写 MySQL 模型 / DAO spec/04-data-model/mysql.md
写 Redis 缓存 / 分布式锁 spec/04-data-model/redis.md
写测试 spec/06-testing/unit.md
写 migration spec/13-database-migration/migration.md
加日志 / 指标 / 追踪 spec/10-observability/{logging,metrics,tracing}.md
实现登录 / 鉴权 spec/11-security/auth.md
写 PRD / RFC / ADR / HLD docs/templates/ 对应模板
PR 自查 spec/07-code-review.md

核心约束(不可违反,无需打开 spec 也要遵守)

架构

  • 单服务:cmd → server → service → biz → data → model,禁止跨层(service 不能直连 data
  • monorepo:cmd/ 按 service 切、internal/ 按 Bounded Context 切;跨 BC 走 API / 事件 / internal/pkg/
  • 接口在消费方定义,禁止循环依赖
  • 依赖通过构造函数注入

编码

  • 禁止 _ = fn() 忽略错误
  • 共享状态必须加锁,测试必须 -race
  • 错误用 %w 包装;不重复记录
  • 涉及 IO 的函数第一个参数 context.Context
  • init() 仅做注册(pprof / collector / driver),禁止 IO 或可能 panic
  • 避免 any / interface{} 出现在公共 API 边界

API

  • 所有变更先改 .proto,禁止改生成代码
  • Handler 必须有 Swagger 注释(@Summary / @Router / @Success
  • 响应统一 {code, message, data}
  • 破坏性变更走新版本

测试

  • 新功能必须有单元测试
  • CI 强制 -race
  • E2E 必须清理数据

Git

  • 提交格式:<type>(<scope>): <desc>
  • 禁止提交敏感信息
  • 禁止 force push main/master

构建 / 交付

  • 所有构建 / 产物 / 部署目标必须走根 Makefilemake build / make image / make deploy-*
  • CI / README / 本地开发统一调 make <target>,禁止直接 go build / docker build / kubectl
  • 生产部署 target 有审批保护

可观测性

  • 暴露 /healthz /readyz /metrics
  • 日志结构化 + trace_id
  • 高基数字段(user_id / email / url)禁止做 Prometheus label
  • 敏感字段禁止明文入日志

Read the full file on GitHub · 95 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 · 95 lines · 0 tokens per session scan A f752d1d3c618

Subscribe to this mod's changes

cursor-rule-template is a cursor rule published in the GitHub repository singchia/gospec (5 stars, last pushed 4mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,234 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.