Golang Patterns
Idiomatic Go patterns, best practices, and conventions for building robust, efficient, and maintainable Go applications.
Install
/plugin marketplace add xu-xiang/everything-claude-code-zhThe repo is a Claude Code plugin marketplace. Run /plugin afterwards to pick the plugin that includes this skill.
npx skills add xu-xiang/everything-claude-code-zh --skill golang-patternsgit clone --depth 1 https://github.com/xu-xiang/everything-claude-code-zh.git /tmp/everything-claude-code-zh
mkdir -p ~/.claude/skills
cp -r /tmp/everything-claude-code-zh/docs/zh-TW/skills/golang-patterns ~/.claude/skills/golang-patternsPersonal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.
From the SKILL.md
# Go 開發模式
用於建構穩健、高效且可維護應用程式的慣用 Go 模式和最佳實務。
## 何時啟用
- 撰寫新的 Go 程式碼
- 審查 Go 程式碼
- 重構現有 Go 程式碼
- 設計 Go 套件/模組
## 核心原則
### 1. 簡單與清晰
Go 偏好簡單而非聰明。程式碼應該明顯且易讀。
```go
// 良好:清晰直接
func GetUser(id string) (*User, error) {
user, err := db.FindUser(id)
if err != nil {
return nil, fmt.Errorf("get user %s: %w", id, err)
}
return user, nil
}
// 不良:過於聰明
func GetUser(id string) (*User, error) {
return func() (*User, error) {
if u, e := db.FindUser(id); e == nil {
return u, nil
} else {
return nil, e
}
}()
}
```
### 2. 讓零值有用
設計類型使其零值無需初始化即可立即使用。
```go
// 良好:零值有用
type Counter struct {
mu sync.Mutex
count int // 零值為 0,可直接使用
}
func (c *Counter) Inc() {
c.mu.Lock()
c.count++
c.mu.Unlock()
}
// 良好:bytes.Buffer 零值可用
var buf bytes.Buffer
buf.WriteString("hello")
// 不良:需要初始化
type BadCounter struct {
counts map[string]int // nil map 會 panic
}
```
### 3. 接受介面,回傳結構
函式應接受介面參數並回傳具體類型。
```go
// 良好:接受介面,回傳具體類型
func ProcessData(r io.Reader) (*Result, error) {
data, err := io.ReadAll(r)
if err != nil {
return nil, err
}
return &Result{Data: data}, nil
}
// 不良:回傳介面(不必要地隱藏實作細節)
func ProcessData(r io.Reader) (io.Reader, error) {
// ...
}
```
## 錯誤處理模式
### 帶上下文的錯誤包裝Details
- Skill name
golang-patterns- Repository
- xu-xiang/everything-claude-code-zh
- Path
docs/zh-TW/skills/golang-patterns/SKILL.md- License
- MIT
- Repo updated
- 5 March 2026
FAQ
What does the Golang Patterns skill do?
Idiomatic Go patterns, best practices, and conventions for building robust, efficient, and maintainable Go applications.
How do I install the Golang Patterns skill?
Claude Code plugin: /plugin marketplace add xu-xiang/everything-claude-code-zh. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.
Is Golang Patterns popular?
It lives in xu-xiang/everything-claude-code-zh, which has 2,037 GitHub stars and 332 forks.
Related skills
Backend Patterns
2kxu-xiang/everything-claude-code-zh
Backend architecture patterns, API design, database optimization, and server-side best practices for Node.js, Express, and Next.js API routes.
Coding Standards
2kxu-xiang/everything-claude-code-zh
Universal coding standards, best practices, and patterns for TypeScript, JavaScript, React, and Node.js development.
Frontend Patterns
2kxu-xiang/everything-claude-code-zh
Frontend development patterns for React, Next.js, state management, performance optimization, and UI best practices.
Golang Testing
2kxu-xiang/everything-claude-code-zh
Go测试模式包括表格驱动测试、子测试、基准测试、模糊测试和测试覆盖率。遵循TDD方法论,采用地道的Go实践。
Django Verification
2kxu-xiang/everything-claude-code-zh
Django项目的验证循环:迁移、代码检查、带覆盖率的测试、安全扫描,以及在发布或PR前的部署就绪检查。
Golang Testing
2kxu-xiang/everything-claude-code-zh
Go 测试模式,包括表格驱动测试、子测试、基准测试、模糊测试和测试覆盖率。遵循具有惯用 Go 实践的 TDD 方法论。
Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.