g-code-spec

A set of rules for writing and changing Go code according to Uber's Go style guidelines. It covers formatting, imports, names, declarations, and related code conventions.

In plain words
What is it for?
Use it when creating or editing Go packages, interfaces, variables, constants, imports, and long function declarations.
Why use it?
It gives the coding agent consistent Go standards to follow, making code easier for Go developers to read and maintain.

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/xyzbit/ai-coding/g-code-spec
Clone the repo
git clone --depth 1 https://github.com/xyzbit/AI-Coding
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,101 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.01101
Opus 5 $0.00000 $0.00550
Sonnet 5 $0.00000 $0.00220
Haiku 4.5 $0.00000 $0.00110

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

Security

Grade A, and why

g-code-spec 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 yesterday.

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/rules/g-code-spec.mdc · 230 lines

How it starts

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

Golang Cursor Rules

你是一位遵循 Uber Go 编码规范的 Golang 专家。在生成和修改代码时必须遵循以下规范:

代码格式

  1. 行长度控制
// 不要超过 120 个字符
// Bad
func (r *SomeType) SomeLongFunctionName(someArg1 Type1, someArg2 Type2, someArg3 Type3, someArg4 Type4, someArg5 Type5) (Type6, error) {
    // ...
}

// Good
func (r *SomeType) SomeLongFunctionName(
    someArg1 Type1,
    someArg2 Type2,
    someArg3 Type3,
    someArg4 Type4,
    someArg5 Type5,
) (Type6, error) {
    // ...
}
  1. 声明分组
// Good
const (
    defaultPort = 8080
    defaultUser = "user"
)

var (
    errInvalidUser = errors.New("invalid user")
    errInvalidPort = errors.New("invalid port")
)
  1. import 分组
// Good
import (
    // 标准库
    "fmt"
    "net/http"
    
    // 外部库
    "github.com/pkg/errors"
    "go.uber.org/zap"
    
    // 内部包
    "yourproject/internal/auth"
)

命名规范

  1. 包名
// Bad
package authService

// Good
package auth
  1. 接口命名
// Good - 单方法接口以方法名+er结尾
type Reader interface {
    Read(p []byte) (n int, err error)
}

// Good - 双方法接口可以组合两个名词
type ReadWriter interface {
    Reader
    Writer
}
  1. 变量命名
// Bad
var UserMap map[string]*User

// Good
var usersByID map[string]*User

// Bad
const TTL = 60

// Good
const timeToLive = 60

编程范式

  1. 接口处理
// Bad - 指针接收器
type Handler struct{}
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {}

// Good - 值接收器
type Handler struct{}
func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {}
  1. 错误处理
// Bad
if err != nil {
    log.Fatal(err)
}

// Good
if err != nil {
    return fmt.Errorf("failed to process request: %w", err)
}
  1. 避免使用 init()
// Bad
func init() {
    db.Connect()
}

// Good
func main() {
    if err := db.Connect(); err != nil {
        log.Fatal(err)
    }
}

并发处理

  1. goroutine 管理
// Bad - fire and forget
go process()

// Good - 使用 WaitGroup
var wg sync.WaitGroup
wg.Add(1)
go func() {
    defer wg.Done()
    process()
}()
wg.Wait()
  1. channel 使用
// Bad - 使用带缓冲的 channel
ch := make(chan int, 10)

// Good - 无缓冲 channel 或缓冲大小为 1
ch := make(chan int)
ch := make(chan int, 1)

Read the full file on GitHub · 230 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. yesterday First seen · 230 lines · 1,101 tokens per session scan A faadb15d9ee3

Subscribe to this mod's changes

g-code-spec is a cursor rule published in the GitHub repository xyzbit/AI-Coding (21 stars, last pushed 10mo ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 1,101 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.