go-basics

go-basics is a cursor rule for Cursor from wangqiqi/cursor-ai-rules. It costs 0 tokens per session (2,051 once invoked), scanned C, original, MIT.

A set of development rules for Go, a programming language often used for web services, distributed systems, command-line tools, and infrastructure software. It covers project layout and practices for these kinds of applications.

In plain words
What is it for?
Use it when building Go APIs, microservices, containerized or distributed applications, command-line programs, high-concurrency servers, and DevOps or infrastructure tools.
Why use it?
It gives a Go project a consistent structure, making files and responsibilities easier to find as the codebase grows. It also provides guidance for common service and systems-programming work.

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/wangqiqi/cursor-ai-rules/go-basics
Clone the repo
git clone --depth 1 https://github.com/wangqiqi/cursor-ai-rules

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 go-basics

README.md
[![agentmods](https://agentmods.dev/badge/rules/wangqiqi/cursor-ai-rules/go-basics.svg)](https://agentmods.dev/rules/wangqiqi/cursor-ai-rules/go-basics)
Your own site
<a href="https://agentmods.dev/rules/wangqiqi/cursor-ai-rules/go-basics"><img src="https://agentmods.dev/badge/rules/wangqiqi/cursor-ai-rules/go-basics.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 2,051 The whole file, excluding the scripts and references it only reads on demand.
Security scan C 1 finding. 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.02051
Opus 5 $0.00000 $0.01026
Sonnet 5 $0.00000 $0.00410
Haiku 4.5 $0.00000 $0.00205

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

Security

Grade C, and why

go-basics scanned grade C with 1 finding 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 4d 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.

Recursive force deletehighDestructive command

rm -rf with a variable or a broad path is one typo away from removing the wrong tree.

rm -rf vendor/
.cursor/rules/tech/go-basics.mdc · 321 lines

How it starts

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

🚀 Go 开发规则

版本: v4.3.0 | 最后更新: 2026-01-22 | 作者: Cursor AI Rules

🎯 适用场景

  • 云原生微服务开发
  • 网络服务和API服务
  • 分布式系统和容器化应用
  • 系统工具和命令行程序
  • 高并发服务器应用
  • DevOps工具和基础设施代码

🏗️ 项目结构

Go Modules 项目布局

go_project/
├── go.mod                    # Go模块定义
├── go.sum                    # 依赖校验文件
├── main.go                   # 程序入口
├── cmd/                      # 主程序
│   └── server/
│       └── main.go
├── internal/                 # 私有代码
│   ├── config/              # 配置管理
│   │   ├── config.go
│   │   └── config_test.go
│   ├── models/              # 数据模型
│   │   ├── user.go
│   │   └── product.go
│   ├── handlers/            # HTTP处理器
│   │   ├── user_handler.go
│   │   └── product_handler.go
│   ├── services/            # 业务逻辑
│   │   ├── user_service.go
│   │   └── product_service.go
│   └── repository/          # 数据访问层
│       ├── user_repo.go
│       └── product_repo.go
├── pkg/                      # 可公开使用的包
│   ├── middleware/
│   └── utils/
├── api/                      # API定义 (protobuf, swagger等)
├── web/                      # Web资源
│   ├── static/
│   └── templates/
├── config/                   # 配置文件
├── scripts/                  # 构建和部署脚本
├── docker/                   # Docker相关
├── docs/                     # 文档
├── Makefile                  # 构建脚本
├── Dockerfile               # Docker镜像定义
└── README.md

包结构设计原则

module github.com/yourname/project

// 清晰的分层架构
├── main.go (程序入口)
├── cmd/ (具体应用)
├── internal/ (私有包)
│   ├── app/ (应用层)
│   ├── domain/ (领域层)
│   └── infrastructure/ (基础设施层)
└── pkg/ (公共包)
    ├── api/ (API定义)
    └── shared/ (共享工具)

📝 编码规范

Effective Go 实践

package main

import (
    "context"
    "database/sql"
    "encoding/json"
    "fmt"
    "log"
    "net/http"
    "time"
)

// ✅ 推荐:清晰的包命名和导入分组
import (
    "context"
    "net/http"

    "github.com/gorilla/mux"
    "github.com/yourname/project/internal/models"
)

// ✅ 推荐:使用结构体标签和JSON序列化
type User struct {
    ID        int64     `json:"id" db:"id"`
    Username  string    `json:"username" db:"username" validate:"required,min=3,max=50"`
    Email     string    `json:"email" db:"email" validate:"required,email"`
    CreatedAt time.Time `json:"created_at" db:"created_at"`
    UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}

// ✅ 推荐:构造函数模式
func NewUser(username, email string) (*User, error) {
    if username == "" || email == "" {
        return nil, fmt.Errorf("username and email are required")
    }

    return &User{
        Username:  username,
        Email:     email,
        CreatedAt: time.Now(),
        UpdatedAt: time.Now(),
    }, nil
}

// ✅ 推荐:接口定义和依赖注入
type UserRepository interface {
    Create(ctx context.Context, user *User) error
    GetByID(ctx context.Context, id int64) (*User, error)
    Update(ctx context.Context, user *User) error
    Delete(ctx context.Context, id int64) error
}

type UserService struct {
    repo UserRepository
    // 其他依赖...
}

// 构造函数注入依赖
func NewUserService(repo UserRepository) *UserService {
    return &UserService{
        repo: repo,
    }
}

// ✅ 推荐:错误处理模式
func (s *UserService) CreateUser(ctx context.Context, username, email string) (*User, error) {
    user, err := NewUser(username, email)
    if err != nil {
        return nil, fmt.Errorf("failed to create user: %w", err)
    }

    if err := s.repo.Create(ctx, user); err != nil {
        return nil, fmt.Errorf("failed to save user: %w", err)
    }

    return user, nil
}

// ✅ 推荐:Context 传递和超时控制
func (s *UserService) ProcessUserBatch(ctx context.Context, userIDs []int64) error {
    // 创建带超时的上下文
    ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
    defer cancel()

    // 使用goroutine处理批量操作
    semaphore := make(chan struct{}, 10) // 限制并发数
    errChan := make(chan error, len(userIDs))

    for _, userID := range userIDs {
        go func(id int64) {
            semaphore <- struct{}{} // 获取信号量
            defer func() { <-semaphore }() // 释放信号量

            if err := s.processSingleUser(ctx, id); err != nil {
                errChan <- err
                return
            }
            errChan <- nil
        }(userID)
    }

    // 收集结果
    for i := 0; i < len(userIDs); i++ {
        if err := <-errChan; err != nil {
            return err
        }
    }

    return nil
}

func (s *UserService) processSingleUser(ctx context.Context, userID int64) error {
    select {
    case <-ctx.Done():
        return ctx.Err()
    default:
        // 处理单个用户
        return nil
    }
}

Read the full file on GitHub · 321 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. 4d ago First seen · 321 lines · 0 tokens per session scan C ce631b00b82a

Subscribe to this mod's changes

go-basics is a cursor rule published in the GitHub repository wangqiqi/cursor-ai-rules (16 stars, last pushed 3mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,051 tokens. A static security scan graded it C with 1 finding (recursive force delete). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.