원클릭으로
go-development
Go 语言开发技能,专注于 Fiber Web 框架、Cobra CLI、GORM ORM、整洁架构和并发编程。使用此技能构建 Go Web 应用、开发 CLI 工具、实现 RESTful API,或需要 Go 架构设计和性能优化指导时使用。
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Go 语言开发技能,专注于 Fiber Web 框架、Cobra CLI、GORM ORM、整洁架构和并发编程。使用此技能构建 Go Web 应用、开发 CLI 工具、实现 RESTful API,或需要 Go 架构设计和性能优化指导时使用。
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Expert Git skills covering interactive rebase, worktree management, reflog recovery, bisect debugging, advanced workflows, commit message best practices, and clean history management. Use this skill when needing advanced Git operations, cleaning commit history, managing multiple worktrees, recovering lost commits, debugging with bisect, or implementing sophisticated Git workflows.
Go language development skill focusing on Fiber web framework, Cobra CLI, GORM ORM, Clean Architecture, and concurrent programming. Use this skill when building Go web applications, developing CLI tools with Cobra, implementing RESTful APIs with Fiber, or need guidance on Go architecture design and performance optimization.
Skill for summarizing the current session's context, including completed tasks, technical decisions, and next steps. Use this skill when you need to create a handover document for a new session, switch contexts without losing critical information, or document what was accomplished before ending a session.
Provides core Swift 6+ language development capabilities, covering concurrency, macros, model design, and business logic. Use this skill when writing ViewModel, Service, or Repository layer code, defining data models, implementing algorithms, writing unit tests, or fixing concurrency warnings and data races.
Specialized in building user interfaces using modern SwiftUI, covering NavigationStack, Observation framework, and SwiftData integration. Use this skill when writing SwiftUI view files, designing app navigation, handling animations and transitions, or binding ViewModel data to the interface.
System architecture design skill covering architecture patterns, distributed systems, technology selection, and enterprise architecture documentation. Use this skill when designing system architectures, evaluating technology stacks, planning distributed systems, or creating architecture decision records and documentation.
| name | go-development |
| description | Go 语言开发技能,专注于 Fiber Web 框架、Cobra CLI、GORM ORM、整洁架构和并发编程。使用此技能构建 Go Web 应用、开发 CLI 工具、实现 RESTful API,或需要 Go 架构设计和性能优化指导时使用。 |
你是一名专家级 Go 开发者,拥有 10 年以上使用现代 Go 实践构建高性能、可扩展应用的经验,专精于 Fiber Web 框架、Cobra CLI 开发和 GORM ORM。
始终使用以下结构:
project/
├── cmd/ # 入口点
│ ├── api/ # API 服务器
│ └── cli/ # CLI 工具
├── internal/ # 私有应用代码
│ ├── domain/ # 领域层(实体、接口)
│ │ └── user/
│ │ ├── entity.go # 领域实体
│ │ ├── repository.go # 仓储接口
│ │ └── service.go # 服务接口
│ ├── usecase/ # 用例层(业务逻辑)
│ │ └── user/
│ │ └── service.go # 服务实现
│ ├── adapter/ # 适配器层
│ │ ├── handler/ # HTTP 处理器
│ │ └── repository/ # 仓储实现
│ ├── infrastructure/ # 基础设施
│ │ ├── database/
│ │ ├── logger/
│ │ └── config/
│ └── dto/ # 数据传输对象
├── pkg/ # 公共可重用包
│ ├── errors/
│ ├── middleware/
│ └── validator/
├── config/
├── migrations/
└── test/
标准文件模板(领域实体、仓储接口/实现、服务接口/实现、Fiber HTTP处理器、DTO、Cobra CLI命令):参见 references/file-templates.md
// ✅ 好:使用上下文包装错误
func (s *service) GetUser(ctx context.Context, id string) (*User, error) {
user, err := s.repo.GetByID(ctx, id)
if err != nil {
return nil, errors.Wrap(err, "failed to get user from repository")
}
return user, nil
}
// ✅ 好:使用 errors.Is 进行比较
if errors.Is(err, user.ErrNotFound) {
return c.Status(fiber.StatusNotFound).JSON(...)
}
// ❌ 差:忽略错误
func (s *service) DoSomething() {
_ = s.repo.Save(user) // 不要忽略错误!
}
// ❌ 差:字符串比较
if err.Error() == "user not found" { // 脆弱!
// ...
}
// ✅ 好:始终传递和检查 context
func (s *service) ProcessOrder(ctx context.Context, orderID string) error {
// Check if context is cancelled
select {
case <-ctx.Done():
return ctx.Err()
default:
}
// Pass context downstream
order, err := s.repo.GetOrder(ctx, orderID)
if err != nil {
return err
}
// Use timeout context for external calls
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
return s.externalAPI.Process(ctx, order)
}
// ❌ 差:不传递 context
func (s *service) GetUser(id string) (*User, error) {
return s.repo.GetByID(id) // 缺少 context!
}
// ✅ 好:使用 errgroup 处理多个 goroutine
import "golang.org/x/sync/errgroup"
func (s *service) FetchMultiple(ctx context.Context, ids []string) ([]*User, error) {
g, ctx := errgroup.WithContext(ctx)
results := make([]*User, len(ids))
for i, id := range ids {
i, id := i, id // Capture loop variables
g.Go(func() error {
user, err := s.repo.GetByID(ctx, id)
if err != nil {
return err
}
results[i] = user
return nil
})
}
if err := g.Wait(); err != nil {
return nil, err
}
return results, nil
}
// ✅ 好:使用 sync.WaitGroup 进行不需要返回值的操作
func (s *service) NotifyUsers(users []*User) {
var wg sync.WaitGroup
for _, u := range users {
wg.Add(1)
go func(user *User) {
defer wg.Done()
s.notifier.Send(user.Email, "message")
}(u)
}
wg.Wait()
}
// ❌ 差:goroutine 泄漏
func (s *service) Subscribe() {
go func() {
for { // 没有办法停止!
s.processMessages()
}
}()
}
// ✅ 好:使用 preload 避免 N+1 查询
users, err := r.db.Preload("Orders").Find(&users).Error
// ✅ 好:使用事务处理多个操作
err := r.db.Transaction(func(tx *gorm.DB) error {
if err := tx.Create(&user).Error; err != nil {
return err
}
if err := tx.Create(&profile).Error; err != nil {
return err
}
return nil
})
// ✅ 好:使用批量插入
r.db.CreateInBatches(users, 100)
// ❌ 差:N+1 查询问题
users, _ := r.db.Find(&users).Error
for _, user := range users {
orders, _ := r.db.Where("user_id = ?", user.ID).Find(&orders).Error // N 次查询!
}
// ✅ 好:构造函数注入接口
type UserService struct {
repo user.Repository // 接口,不是具体类型
cache cache.Cache
logger logger.Logger
}
func NewUserService(
repo user.Repository,
cache cache.Cache,
logger logger.Logger,
) *UserService {
return &UserService{
repo: repo,
cache: cache,
logger: logger,
}
}
// ❌ 差:内部直接实例化
type UserService struct {
repo *PostgresRepo // 具体类型!
}
func NewUserService() *UserService {
return &UserService{
repo: &PostgresRepo{}, // 紧耦合!
}
}