Agent SkillsTaoidle/plan-cascade › go-best-practices

go-best-practices

GitHub

提供Go语言编码最佳实践,涵盖代码风格、错误处理、并发模式、项目结构及测试规范。适用于编写或审查Go代码时参考,确保代码符合惯用模式并避免常见反模式。

builtin-skills/go/SKILL.md Taoidle/plan-cascade

Trigger Scenarios

编写Go代码 审查Go代码 解决Go并发问题 设计Go项目结构

Install

npx skills add Taoidle/plan-cascade --skill go-best-practices -g -y
More Options

Non-standard path

npx skills add https://github.com/Taoidle/plan-cascade/tree/master/builtin-skills/go -g -y

Use without installing

npx skills use Taoidle/plan-cascade@go-best-practices

指定 Agent (Claude Code)

npx skills add Taoidle/plan-cascade --skill go-best-practices -a claude-code -g -y

安装 repo 全部 skill

npx skills add Taoidle/plan-cascade --all -g -y

预览 repo 内 skill

npx skills add Taoidle/plan-cascade --list

SKILL.md

Frontmatter
{
    "name": "go-best-practices",
    "license": "MIT",
    "metadata": {
        "author": "plan-cascade",
        "version": "1.0.0"
    },
    "description": "Go coding best practices. Use when writing or reviewing Go code. Covers error handling, concurrency, and idiomatic patterns."
}

Go Best Practices

Code Style

Rule Guideline
Formatter gofmt or goimports
Linter golangci-lint
Naming Short, clear; avoid stuttering
Comments Godoc for exported items

Error Handling

Rule Guideline
Always check Never ignore errors
Wrap context fmt.Errorf("ctx: %w", err)
Sentinel errors var ErrNotFound = errors.New(...)
func Load(path string) (*Config, error) {
    data, err := os.ReadFile(path)
    if err != nil {
        return nil, fmt.Errorf("load config %s: %w", path, err)
    }
    // ...
}

Project Structure

cmd/appname/main.go
internal/config/
internal/service/
go.mod

Concurrency

Pattern Usage
context.Context Cancellation, timeouts
sync.WaitGroup Wait for goroutines
errgroup.Group Goroutines with errors
func Process(ctx context.Context, items []Item) error {
    for _, item := range items {
        select {
        case <-ctx.Done():
            return ctx.Err()
        default:
            if err := process(item); err != nil { return err }
        }
    }
    return nil
}

Anti-Patterns

Avoid Use Instead
Naked returns Explicit returns
panic for errors Return errors
Large interfaces Small, focused
init() Explicit init

Testing (Table-Driven)

func TestParse(t *testing.T) {
    tests := []struct{ name, input string; want int; wantErr bool }{
        {"valid", "42", 42, false},
        {"invalid", "abc", 0, true},
    }
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            got, err := Parse(tt.input)
            if (err != nil) != tt.wantErr { t.Errorf("err=%v, want=%v", err, tt.wantErr) }
            if got != tt.want { t.Errorf("got=%v, want=%v", got, tt.want) }
        })
    }
}

Version History

  • 5223f82 Current 2026-07-19 09:26

Same Skill Collection

builtin-skills/java/SKILL.md
builtin-skills/python/SKILL.md
builtin-skills/typescript/SKILL.md
skills/hybrid-ralph/SKILL.md
skills/mega-plan/SKILL.md
skills/planning-with-files/SKILL.md

Metadata

Files
0
Version
5223f82
Hash
30a17c46
Indexed
2026-07-19 09:26

Home - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-07-21 05:26
浙ICP备14020137号-1 $Map of visitor$