SKILL·3C21DE

go-code-review

eduardo-sl
更新于 8 days ago
64
9
64
在 GitHub 上查看
测试testing

关于

This skill provides a structured checklist for reviewing Go code, focusing on idiomatic patterns, error handling, and test coverage. It operates in modes for reviewing diffs (like PRs) or full files/packages. Use it for general code quality reviews, not for security or performance-specific audits.

快速安装

Claude Code

推荐
主要方式
npx skills add eduardo-sl/go-agent-skills -a claude-code
插件命令备选方式
/plugin add https://github.com/eduardo-sl/go-agent-skills
Git 克隆备选方式
git clone https://github.com/eduardo-sl/go-agent-skills.git ~/.claude/skills/go-code-review

在 Claude Code 中复制并粘贴此命令以安装该技能

技能文档

Go Code Review

Structured code review process for Go. Reviews should be constructive, specific, and cite the relevant principle behind each finding.

Operating Modes

Pick the mode that matches the request before starting:

  • Diff review (default) — review only the changed lines plus enough surrounding context to judge them. Use for PRs and working-tree changes.
  • File/package review — review the named files or packages in full, including their tests.
  • Full audit — sweep the entire codebase. Use the strategy in "Auditing Large Codebases" below and aggregate everything into one report.

Review Process

Execute these steps in order. For each finding, classify severity:

  • 🔴 BLOCKER — Must fix before merge. Correctness, data loss, security.
  • 🟡 WARNING — Should fix. Maintainability, idiomatic Go, clarity.
  • 🟢 SUGGESTION — Consider improving. Style, naming, documentation.

0. Run the Toolchain First

Before reading code manually, let the tools catch the mechanical issues (skip any tool that is not installed and note it in the report):

go build ./...          # it must compile
go vet ./...            # suspicious constructs
golangci-lint run       # if the repo has a config
go test -race ./...     # tests pass, no data races

Report tool findings alongside manual findings — a failing go vet is an automatic 🔴 BLOCKER. Never report an issue a tool already proves absent.

1. Correctness & Safety

Error Handling

  • Every error is checked. No blank identifier _ discarding errors silently.
  • Errors are wrapped with context: fmt.Errorf("fetch user %d: %w", id, err).
  • Error values compared with errors.Is() / errors.As(), never ==.
  • No panic outside of init() or truly unrecoverable situations.
  • Errors handled exactly once — no log-and-return patterns.

Nil Safety

  • Pointer receivers checked before dereference when nil is a valid state.
  • Map reads guarded or use comma-ok idiom.
  • Channel operations consider closed/nil channels.
  • Slice operations check bounds where relevant.

Concurrency

  • Shared mutable state protected by sync.Mutex or channels.
  • No goroutine leaks — every goroutine has a clear termination path.
  • Context propagation: all blocking calls accept and respect context.Context.
  • sync.WaitGroup or errgroup.Group used for goroutine lifecycle.

2. API Design

  • Exported functions have doc comments starting with the function name.
  • Accept interfaces, return concrete types.
  • Use functional options (WithTimeout(d)) over config structs for optional params.
  • Context is always the first parameter: func Foo(ctx context.Context, ...).
  • Return error as the last return value.
  • Avoid bool parameters — prefer named types or options.

3. Idiomatic Go

  • Uses := for local variables, var for zero-value intent.
  • No unnecessary else after return/continue/break.
  • Guard clauses and early returns reduce nesting.
  • defer used for cleanup, placed right after resource acquisition.
  • range used over manual index iteration where appropriate.
  • Struct literals use field names.
  • Interfaces defined at consumer, not producer.

4. Package Structure

  • Package names are short, lowercase, singular nouns.
  • No circular dependencies between packages.
  • internal/ used for non-public packages.
  • cmd/ contains main packages, one per binary.
  • Clear separation of concerns — no god packages.

5. Testing

  • Test functions follow TestXxx naming convention.
  • Table-driven tests used for multiple input/output combinations.
  • Test helpers use t.Helper() for clean stack traces.
  • No test logic in init() — use TestMain when needed.
  • Tests use testify/assert or testify/require consistently, or stdlib only.
  • Edge cases covered: empty input, nil, zero values, max values.
  • t.Parallel() used where safe.

6. Documentation

  • All exported types, functions, and constants have doc comments.
  • Doc comments start with the name of the entity.
  • Package-level doc comment in doc.go for non-trivial packages.
  • Complex algorithms or business logic have inline comments explaining why.

7. Dependencies

  • go.mod has no replace directives in committed code (except monorepos).
  • No unused dependencies.
  • Dependencies are from well-maintained, reputable sources.
  • Indirect dependencies are understood and acceptable.

Auditing Large Codebases

When the scope exceeds ~20 files, do not read everything in one linear pass. Split the audit into independent passes:

  1. Enumerate packages (go list ./...) and group them by layer (handlers, services, stores, shared libraries).
  2. Run one focused pass per concern from sections 1-7 (correctness, API design, idioms, structure, testing, docs, dependencies).
  3. If your environment supports delegating work to parallel sub-agents or tasks, assign each pass to one — they are independent by design. Otherwise run them sequentially, one concern at a time.
  4. Require every finding to cite file.go:line and severity so the final aggregation is mechanical: merge, deduplicate, sort by severity.

Review Output Format

## Code Review Summary

**Files reviewed:** <list>
**Overall assessment:** APPROVE | REQUEST CHANGES | COMMENT

### Findings

#### 🔴 BLOCKER: <title>
- **File:** `path/to/file.go:42`
- **Issue:** <what is wrong>
- **Why:** <which principle or guideline>
- **Fix:** <concrete suggestion>

#### 🟡 WARNING: <title>
...

#### 🟢 SUGGESTION: <title>
...

### What's Done Well
<genuine positive observations — always include at least one>

GitHub 仓库

eduardo-sl/go-agent-skills
路径: skills/(code-quality)/go-code-review
0
FAQ

常见问题

什么是 go-code-review Skill?

go-code-review 是一个 Claude Skill,作者为 eduardo-sl。Skill 将 Claude 按需加载的说明和资源打包,让 Claude 无需额外提示即可执行与 go-code-review 相关的任务。

如何安装 go-code-review?

使用本页的安装命令:将 go-code-review 作为插件添加到 Claude Code,或将其仓库克隆到 skills 目录,然后重启 Claude 以加载该 Skill。

go-code-review 属于哪个分类?

go-code-review 属于测试分类。

go-code-review 可以免费使用吗?

可以。go-code-review 已收录在 AIMCP,可免费安装。

相关推荐技能

evaluating-llms-harness
测试

该Skill通过60+个学术基准测试(如MMLU、GSM8K等)评估大语言模型质量,适用于模型对比、学术研究及训练进度追踪。它支持HuggingFace、vLLM和API接口,被EleutherAI等行业领先机构广泛采用。开发者可通过简单命令行快速对模型进行多任务批量评估。

查看技能
cloudflare-cron-triggers
测试

这个Claude Skill提供了关于Cloudflare Cron Triggers的完整知识库,用于通过cron表达式定时执行Workers。它支持配置周期性任务、维护作业和自动化工作流,并能处理常见的cron触发错误。开发者可以用它来设置定时任务、测试cron处理器,并集成Workflows和Green Compute功能。

查看技能
webapp-testing
测试

该Skill为开发者提供了基于Playwright的本地Web应用测试工具集,支持自动化测试前端功能、调试UI行为、捕获屏幕截图和查看浏览器日志。它包含管理服务器生命周期的辅助脚本,可直接作为黑盒工具运行而无需阅读源码。适用于需要快速验证本地Web应用界面和交互功能的开发场景。

查看技能
finishing-a-development-branch
测试

这个Skill用于开发分支完成后的集成决策,当代码实现完成且测试通过时,它会引导开发者选择合适的工作流。它首先验证测试状态,然后提供合并、创建PR或清理等结构化选项。核心价值在于确保代码质量的同时,标准化分支收尾流程。

查看技能