Help us improve
Share bugs, ideas, or general feedback.
From golang
Go 1.23+ 核心开发规范:强制约定、代码格式、新特性(range-over-func/slog/min/max/clear)、提交检查清单。编写Go代码时自动加载。
npx claudepluginhub lazygophers/ccplugin --plugin golangHow this skill is triggered — by the user, by Claude, or both
Slash command
/golang:coresonnetThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- **dev** - 开发专家(主要使用者)
Go development standards covering naming conventions, error handling, concurrency patterns, testing practices, and performance optimization for high-quality Go codebases.
Applies Go best practices for performance, modern syntax, generics, patterns, testing, error handling, and concurrency when writing or reviewing Go code.
Provides idiomatic Go patterns and best practices for error handling, concurrency like worker pools, simplicity, zero values, and interfaces. Activates for writing, reviewing, refactoring, or designing Go code.
Share bugs, ideas, or general feedback.
| 场景 | Skill | 说明 |
|---|---|---|
| 处理错误 | Skills(golang:error) | 错误处理规范:禁止单行 if err、必须记录日志 |
| 使用工具库 | Skills(golang:libs) | 优先库规范:stringx/candy/osx/log |
| 命名变量/类型 | Skills(golang:naming) | 命名规范:Id/Uid/IsActive/CreatedAt |
| 设计架构 | Skills(golang:structure) | 项目结构规范:三层架构、全局状态模式 |
| 写测试 | Skills(golang:testing) | 测试规范:表驱动测试、模糊测试 |
| 写并发代码 | Skills(golang:concurrency) | 并发规范:atomic/sync.Pool/errgroup/iter |
| 配置/运行 lint | Skills(golang:lint) | Lint 规范:golangci-lint v2 配置 |
| 运行工具 | Skills(golang:tooling) | 工具规范:gofmt/goimports/govulncheck |
Go 生态追求高性能、低分配、简洁优雅。
三个支柱:
// 结构化日志(标准库)
import "log/slog"
slog.Info("user registered", "username", name, "email", email)
// 内置 min/max/clear
m := min(a, b)
M := max(a, b)
clear(mySlice) // 清空 slice
clear(myMap) // 清空 map
// for-range 整数
for i := range 10 {
fmt.Println(i) // 0..9
}
// net/http 增强路由模式
mux.HandleFunc("GET /api/users/{id}", getUser)
mux.HandleFunc("POST /api/users", createUser)
// range-over-func 迭代器
import "maps"
import "slices"
for k, v := range maps.All(m) {
fmt.Println(k, v)
}
for i, v := range slices.All(s) {
fmt.Println(i, v)
}
// 自定义迭代器
func (t *Tree[V]) All() iter.Seq2[string, V] {
return func(yield func(string, V) bool) {
// ...
}
}
if err != nil { return err }gofmt -w .
goimports -w .
import (
// 标准库
"context"
"fmt"
"os"
"time"
// 第三方库
"github.com/gofiber/fiber/v2"
"github.com/lazygophers/log"
"gorm.io/gorm"
// 项目内部
"github.com/username/project/internal/state"
"github.com/username/project/internal/impl"
)
package main
import ()
const ()
var ()
type MyType struct {}
type MyInterface interface {}
func main() {}
// User 表示系统用户
type User struct {
Id int64
Email string
IsActive bool
CreatedAt time.Time
}
// UserLogin 处理用户登录逻辑
func UserLogin(req *LoginReq) (*User, error) {}
| AI 可能的理性化解释 | 实际应该检查的内容 | 严重程度 |
|---|---|---|
| "单行 if err 更简洁" | 是否所有 error 都多行处理? | 高 |
| "for 循环更直观" | 是否使用 candy 库操作集合? | 高 |
| "fmt.Errorf 能加上下文" | 是否禁止包装错误,直接返回原始? | 高 |
| "Go 1.18 泛型就够了" | 是否使用了 Go 1.23 新特性(iter、min/max)? | 低 |
| "Repository 接口更灵活" | 是否使用全局 State 模式? | 高 |
| "导出函数不用注释" | 是否所有导出类型/函数有注释? | 中 |