AgentLint 实测验证 100/100基于 210 个 Go 开源仓库统计

    Go CLAUDE.md & AGENTS.md 模板

    表驱动测试、-race 竞态检测与 %w 显式错误包装,提炼自 210 个 Go 仓库。

    # Go Project — Go Service Harness
    
    Go 1.23 service using standard library HTTP/gRPC patterns, `golangci-lint`, and race-checked tests.
    
    ## Commands
    
    - Fast targeted test: `go test ./internal/pkg/... -run TestTarget -v`
    - Full race-checked suite: `go test -race ./...`
    - Lint & vet: `golangci-lint run && go vet ./...`
    - Build: `go build ./...`
    
    ## Rules
    
    - Don't discard errors with `_` or log-and-continue silently. Instead wrap and return them with `fmt.Errorf("context: %w", err)`. Because swallowed errors obscure root causes in production traces.
    - Don't add third-party frameworks when the Go standard library solves the problem cleanly. Instead prefer `net/http`, `context`, and `slog`. Because minimal dependencies keep binaries auditable.
    - Write table-driven unit tests for every exported function and run `go test -race` before finalizing concurrency edits.
    - When editing protobuf schemas, read `proto/README.md` before regenerating stubs.
    
    ## Continuity
    
    - Keep `.env` and `CLAUDE.local.md` gitignored and summarize open items in `HANDOFF.md`.

    Go 开源生态中最常采用的工程规则

    基于 4,533 仓库研究中 210 个公开 Go 仓库的实测统计:

    unit-tests测试

    Write unit tests for all changes

    44.3%93 个仓库
    error-handling代码规范

    Proper error handling with context

    38.1%80 个仓库
    golangci-lint工具链

    Use golangci-lint

    34.8%73 个仓库
    docker工具链

    Docker for containerization

    34.8%73 个仓库
    conventional-commits工作流

    Use conventional commit messages

    29.0%61 个仓库
    error-wrapping代码规范

    Wrap errors with context using %w

    27.6%58 个仓库
    go-vet工具链

    Run go vet before committing

    26.7%56 个仓库
    testify测试

    Use testify for assertions

    24.3%51 个仓库
    必写验证命令(对应规则 W1 与 W7)
    安装依赖
    go mod download
    快速单测(秒级迭代)
    go test ./pkg/target/... -run TestName -v
    全量测试
    go test -race ./...
    Lint 与静态检查
    golangci-lint run && go vet ./...
    生产构建
    go build ./...
    Go 项目中 AI 代理常见踩坑
    • 01AI 用 _ 丢弃返回的 error 或直接吞掉错误上下文。
    • 02跳过 -race 检测会把 goroutine 数据竞争留到生产高并发才爆炸。

    更多实证验证模板