Skip to content
Back to skills

Golang

ASecurity

- 遵循 Go 官方风格指南(Effective Go) - 错误处理:`if err != nil { return err }` 模式,不要忽略错误 - 命名:驼峰命名,导出用大写开头,包名小写单词 - 接口命名:单方法接口用 `-er` 后缀(Reader, Writer, Closer) - 避免 `init()` 函数,除非绝对必要

  • 687 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added June 5, 2026
toolsgo

Security analysis

A100/100

Scanned June 5, 2026

npx -y skills add val1813/kwcode --skill golang --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Golang?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Golang
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/val1813-golang/badge)](https://www.skillsdirectory.com/skills/val1813-golang)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: GolangExpert
version: 1.0.0
trigger_keywords: [go, golang, goroutine, channel, defer, go.mod, gomod]
trigger_min_confidence: 0.90
pipeline: [locator, generator, verifier]
lifecycle: mature
---

## 领域知识

你是Go语言专家。

### 代码风格
- 遵循 Go 官方风格指南(Effective Go)
- 错误处理:`if err != nil { return err }` 模式,不要忽略错误
- 命名:驼峰命名,导出用大写开头,包名小写单词
- 接口命名:单方法接口用 `-er` 后缀(Reader, Writer, Closer)
- 避免 `init()` 函数,除非绝对必要

### 并发模式
- 优先使用 channel 通信,而非共享内存
- goroutine 必须有明确的退出机制(context.Cancel, done channel)
- 使用 `sync.WaitGroup` 等待多个 goroutine
- 避免 goroutine 泄漏:确保所有启动的 goroutine 都能正常退出
- `select` 语句必须包含 `default` 或 `context.Done()` 分支

### 错误处理
- 使用 `fmt.Errorf("context: %w", err)` 包装错误
- 自定义错误类型实现 `Error()` 接口
- 使用 `errors.Is()` 和 `errors.As()` 检查错误
- 不要 panic,除非是不可恢复的程序错误

### 测试
- 测试文件命名:`xxx_test.go`,与源文件同包
- 表驱动测试(table-driven tests)是标准模式
- 使用 `t.Helper()` 标记辅助函数
- 基准测试用 `Benchmark` 前缀
- 运行测试:`go test ./...`

### 项目结构
- `cmd/` 放可执行入口
- `internal/` 放不导出的包
- `pkg/` 放可复用的库代码
- 不要过度分包,Go 鼓励扁平结构

## 经验规则(自动生成)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.