plugins/languages/golang/skills/tooling/SKILL.md
Go 工具链规范——gofmt/goimports 格式化、go mod 依赖管理 + tool 指令(Go 1.24+)、toolchain 指令、golangci-lint v2 + govulncheck 安全扫描、delve 调试、go test -fuzz 模糊测试、pprof + trace 性能分析、go fix 现代化(Go 1.26 重写)、交叉编译。装环境、跑命令、配置 Makefile/CI、做基线检查时触发。
npx skillsauth add lazygophers/ccplugin golang-toolingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
gofmt -w .
goimports -w .
编辑器配置:
{
"go.formatTool": "goimports",
"go.lintTool": "golangci-lint",
"go.lintOnSave": "file",
"go.formatOnSave": true
}
go mod init github.com/username/project
go mod tidy
go get github.com/lazygophers/utils@latest
go list -m all
go mod graph
go.mod 显式声明:
go 1.26.0
toolchain go1.26.0
升级:
go get [email protected]
go get [email protected]
// go.mod
tool golang.org/x/tools/cmd/stringer
tool github.com/golang/mock/mockgen
go tool stringer -type=Status
不再需要 tools.go + //go:build tools 黑魔法。
latest 提交govulncheck ./...go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
govulncheck -mode=binary ./bin/app
详见 golang-lint。
curl -sSfL https://golangci-lint.run/install.sh | sh -s -- -b ./bin v2.12.2
./bin/golangci-lint run ./...
go install github.com/go-delve/delve/cmd/dlv@latest
dlv debug ./cmd/main.go
dlv test ./internal/impl/
dlv attach <pid>
(dlv) b main.main
(dlv) c
(dlv) goroutines
(dlv) bt
(dlv) print user
# 完整测试 + race
go test -v -race -cover ./...
# 模糊测试
go test -fuzz=FuzzParseInput -fuzztime=30s ./parser/
# 基准
go test -bench=. -benchmem -count=5 ./...
benchstat old.txt new.txt
# 覆盖率
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
go tool cover -func=coverage.out | grep total
# CPU/内存
go test -cpuprofile=cpu.prof -memprofile=mem.prof ./...
go tool pprof -http=:8080 cpu.prof
# 线上 endpoint
go tool pprof http://localhost:6060/debug/pprof/heap
go tool pprof http://localhost:6060/debug/pprof/goroutine
# trace
go test -trace=trace.out ./...
go tool trace trace.out
# Goroutine 泄漏剖析(1.26 实验,1.27 拟默认)
GOEXPERIMENT=goroutineleakprofile go build .
# 访问 /debug/pprof/goroutineleak
go fix ./...
Go 1.26 重写后基于 go vet 分析框架,提供数十个 modernizer 自动应用现代语法:
for i := 0; i < n; i++ → for i := range ninterface{} → anyerrors.New(fmt.Sprintf(...)) → fmt.Errorf(...)//go:fix inline 做 API 迁移强烈建议升级 1.26 后跑一次 go fix ./...。
//go:generate protoc --go_out=. ./proto.proto
//go:generate stringer -type=Status
go generate ./...
go build ./...
go build -o bin/app ./cmd/main.go
# 交叉编译
GOOS=linux GOARCH=amd64 go build -o bin/app-linux ./cmd/main.go
GOOS=darwin GOARCH=arm64 go build -o bin/app-mac-arm64 ./cmd/main.go
# 体积优化
go build -ldflags="-s -w" -trimpath -o bin/app ./cmd/main.go
.PHONY: check
check:
gofmt -w .
goimports -w .
go vet ./...
./bin/golangci-lint run ./...
govulncheck ./...
go test -race -cover ./...
| AI 借口 | 实际应验证 | | --- | --- | | "gofmt 够了" | 跑 goimports? | | "go vet 严格" | 跑 golangci-lint v2? | | "依赖没漏洞" | 跑 govulncheck? | | "print 调试" | 用 delve 断点? | | "手管 Go 版本" | go.mod toolchain 指令? | | "tools.go 还在" | 迁到 1.24 tool 指令? | | "没跑 go fix" | 1.26 跑一次现代化? |
gofmt + goimports 已跑go vet ./... 无告警golangci-lint run 通过(v2)govulncheck ./... 无 HIGHgo mod tidy 已跑go.mod 有 toolchain 指令tool 指令(非 tools.go)go test -race -cover ./... 通过go fix ./...tools
UI/UX 与布局设计——做界面布局/结构/导航/组件/交互的设计决策。触发:做UI/UX/布局/排版/导航/组件/交互/栅格/响应式/图表选型/字体配对。按媒介路由 HTML/Web、原生 App(iOS/Android/桌面)、CLI、TUI。需后端动态系统不适用;配色/主题/色板走姊妹 skill design-color。
tools
主题与配色设计——做颜色搭配/调色板/主题/品牌色阶/暗模式的设计决策。触发:选配色/调色/主题/色板/品牌色/暗模式/对比度/色盲/UI风格。按媒介路由 HTML/Web(CSS变量)、原生App(平台token)、CLI(ANSI)、TUI(真彩/256/16降级)。保证可访问性(对比度/色盲安全)。需后端动态系统不适用;UI/UX 布局/组件/交互走姊妹 skill design-uiux。
tools
跨任意组件(plugin/skill/agent/command)的验证驱动优化循环纪律 skill。当用户要优化某个已有组件却无明确方向、或要防止改了反而更差(自评乐观偏差 / 多维同改归因失效 / 为凑分加废话膨胀)、或要把一套通用「评分→单变量改→改后验证严格更好才留否则回滚→触顶停」的纪律套到任意组件上时使用。管优化过程本身的纪律(validation gate / ratchet / 独立验证 / 触顶停),不评单组件深度(交 skill-dev),不查插件接线(交 plugin-dev)。仅手动 /optimize-any 触发。
data-ai
两层规则记忆 (基于 .skein/spec)。planning 时 recall 召回相关规则、task finish 后 sediment 沉淀学习 + prune 自动精简过期/重复/断链规则。core 常驻硬规 + recall 按需召回, 经判定门自动写盘 (不逐次问用户)。产出 .skein/spec 下 core/recall 规则文件 + index。另支持空仓 bootstrap 播种规则基线、记忆大面积失效 (大重构/换栈) 时 reconstruct 可逆归档后按项目类型分型重建、maintain 手动体检 (超预算/stale/断链/重复/废弃, --apply 自动修复)、auto-fix (Stop hook 写 .pending-fix 标记 → main 派 skein-specer bg 跑 maintain --apply 全自动修, 断链只报告)。