Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

Back to skills

Go Dev

ASecurity

Go 开发规范。当用户操作 .go、go.mod、go.sum 文件,或涉及 Go 后端开发(Gin、GORM、Echo)时触发。 包含命名约定、import 顺序、错误处理、并发编程、测试规范、性能优化等。

1,035 stars
0 votes
0 copies
1 views
Added 5/28/2026
ai-agentsgobashsqltestinggit

Security Analysis

A100/100

Scanned 5/28/2026

Install to Claude Code

$npx -y skills add doccker/cc-use-exp --skill go-dev --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Go Dev?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Go Dev
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/doccker-go-dev/badge)](https://www.skillsdirectory.com/skills/doccker-go-dev)

More formats (shields.io, HTML) on the badges page.

Download Zip
Files
SKILL.md
---
name: go-dev
description: >-
  Go 开发规范。当用户操作 .go、go.mod、go.sum 文件,或涉及 Go 后端开发(Gin、GORM、Echo)时触发。
  包含命名约定、import 顺序、错误处理、并发编程、测试规范、性能优化等。
---

# Go 开发规范

> 参考来源: Effective Go、Go Code Review Comments、uber-go/guide

---

## 工具链

```bash
goimports -w .                    # 格式化并整理 import
go vet ./...                      # 静态分析
golangci-lint run                 # 综合检查
go test -v -race -cover ./...     # 测试(含竞态检测和覆盖率)
```

---

## 命名约定

| 类型 | 规则 | 示例 |
|------|------|------|
| 包名 | 小写单词,不用下划线 | `user`, `orderservice` |
| 变量/函数 | 驼峰命名,缩写词一致大小写 | `userID`, `HTTPServer` |
| 常量 | 导出用驼峰,私有可驼峰或全大写 | `MaxRetryCount` |
| 接口 | 单方法用方法名+er | `Reader`, `Writer` |

**禁止**: `common`, `util`, `base` 等无意义包名

---

## import 顺序

```go
import (
    "context"           // 标准库
    "fmt"

    "github.com/gin-gonic/gin"  // 第三方库

    "project/internal/model"     // 项目内部
)
```

---

## 错误处理

**必须处理错误**,不能忽略:

```go
// ✅ 好:添加上下文
if err != nil {
    return fmt.Errorf("failed to query user %d: %w", userID, err)
}

// ❌ 差:忽略错误
result, _ := doSomething()
```

**错误包装**: 使用 `%w` 保留错误链,用 `errors.Is()` / `errors.As()` 检查

---

## 并发编程

**基本原则**:
- 优先使用 channel 通信
- 启动 goroutine 前考虑:谁来等待它?怎么停止它?
- 使用 `context.Context` 控制生命周期

```go
// ✅ 好:使用 context 控制
func process(ctx context.Context) error {
    done := make(chan error, 1)
    go func() { done <- doWork() }()

    select {
    case err := <-done:
        return err
    case <-ctx.Done():
        return ctx.Err()
    }
}
```

**数据竞争**: 使用 `go test -race` 检测

---

## 测试规范

```go
// 表驱动测试
func TestAdd(t *testing.T) {
    tests := []struct {
        name     string
        a, b     int
        expected int
    }{
        {"positive", 1, 2, 3},
        {"zero", 0, 0, 0},
    }

    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            got := Add(tt.a, tt.b)
            if got != tt.expected {
                t.Errorf("Add(%d, %d) = %d, want %d", tt.a, tt.b, got, tt.expected)
            }
        })
    }
}
```

---

## 性能优化

| 陷阱 | 解决方案 |
|------|---------|
| 循环中拼接字符串 | 使用 `strings.Builder` |
| 未预分配 slice | `make([]T, 0, cap)` |
| N+1 查询 | 批量查询 + 预加载 |
| 无限制并发 | 使用 semaphore 或 worker pool |
| Raw SQL 别名用了保留字 | 避免 `year_month`/`order`/`status`/`rank` 等 MySQL 保留字做别名 |

```bash
# 性能分析
go test -cpuprofile=cpu.prof -bench=.
go tool pprof cpu.prof
```

---

## 项目结构

```
project/
├── cmd/                    # 可执行文件入口
├── internal/               # 私有代码
│   ├── handler/
│   ├── service/
│   ├── repository/
│   └── model/
├── pkg/                    # 公共代码
├── go.mod
└── go.sum
```

---

## 详细参考

| 文件 | 内容 |
|------|------|
| `references/go-style.md` | 命名约定、错误处理、并发、测试、性能 |
| `references/date-time.md` | 日期加减、账期计算、AddDate 溢出处理 |

Attribution

docckerdoccker
View sourceMore from doccker →
SSkills DirectorySkills Directory

Know which skills are safe — weekly.

Best new skills + every skill we flagged as malicious. From the team that scanned 103,619.

Join free

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 (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Know which skills are safe — weekly.

Best new skills + every skill we flagged as malicious. From the team that scanned 103,619.

Join free

Related Skills

Caveman

Ultra-compressed communication mode. Cuts token usage ~75% by speaking like caveman while keeping full technical accuracy. Supports intensity levels: lite, full (default), ultra, wenyan-lite, wenyan-full, wenyan-ultra. Use when user says "caveman mode", "talk like caveman", "use caveman", "less tokens", "be brief", or invokes /caveman. Also auto-triggers when token efficiency is requested.

1023331 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

686011 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3351 votes

catchup

Recovers the conversation and failed tool calls of a previous Codex, Claude Code, Antigravity, Cline, Copilot CLI, Cursor, DeepSeek Harness, Kimi, OpenCode, Pi Agent, or ZCode session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", asks to recover/summarize a previous session before continuing, or asks to diagnose or report a catchup failure. Do NOT use for the current conversation, git history, or any non-agent log.

651 votes

math-skill

A comprehensive mathematical reasoning skill for AI assistants — handles arithmetic to research-level problems with rigorous step-by-step reasoning, systematic verification, and transparent uncertainty handling

381 votes
View all in ai-agents →