golang-design-patterns

レビュー · 70
Registry に収録

Idiomatic Golang design patterns — functional options, constructors, error flow and cascading, resource management and lifecycle, graceful shutdown, resilience, architecture, dependency injection, data handling, streaming, and more. Apply when explicitly choosing between architec

Verified installs0
スター3.0K
バージョン1.0.0
品質82/100 · 強い
信頼70/100 · サンドボックス限定
監査84/100 · 要レビュー

供給アセットの概要

コーディングと開発 Agent

コードレビュー、リポジトリ分析、テスト、CI、GitHub、DevOps、開発ワークフロー向けのスキルです。

カテゴリを見る

シナリオ

GitHub automation

I need my agent to triage GitHub issues, review pull requests, and summarize repository changes.

Agent 適合

Claude Code + OpenAI Agents + CLI

Codex、Claude Code、Cursor、CLI、またはカスタム Agent に対応します。

インストール

準備完了

npx skills add samber/cc-skills-golang --skill golang-design-patterns

メンテナンス

新しい

最終プッシュから 1 日

リスク

要レビュー

Dependency or permission surface needs review

GitHub 品質

3.0K

82/100 品質 · 78/100 信頼

対象タグ

コーディングGitHub automationリサーチagent-skill

レビュー注記

Dependency or permission surface needs review · Permission surface may require sandboxing

Agent 導入スコアカード

信頼、監査、インストール準備状況を一目で確認

公開リポジトリのメタデータ、OpenAgentSkill のレビューシグナル、保守の鮮度、インストール準備状況を組み合わせたスコアです。候補選定の目安であり、人によるレビューの代替ではありません。

品質

強い
82

本番ワークフローの候補に値する堅実な選択肢です。

信頼

サンドボックス限定
70

信頼シグナルが不足または混在する有用な候補です。結果ループがタスク適合を示すまで、隔離されたワークスペースで使用してください。

監査

要レビュー
84

インストール準備、安全メタデータ、保守、採用リスクの機械可読なレビュー。

OpenAgentSkill Trust Score v5

インストール前に人のレビュー

実作業で使う前に、サンドボックスでのみ実行し、近い代替と比較してください。

CodexClaude CodeCursorOpenAgentSkill CLI

スター

GitHub スター 3.0K

リポジトリ活動

スター 3.0K、フォーク 197

メンテナンス

最終プッシュから 1 日

ライセンス

MIT

インストール

npx skills add samber/cc-skills-golang --skill golang-design-patterns

インストール安全性

標準パッケージまたはランタイムのインストールパス

権限範囲

shell or command execution, filesystem or document access

Agent の成果

Agent の成果データはまだありません

ドキュメント

README/SKILL.md の文脈が十分です

リスク概要

本番前にレビュー

  • Financial research output is not financial advice; require human review before any live investment decision.
  • Quality score needs review
  • Permission surface needs review: shell or command execution, filesystem or document access
  • Dependency/runtime risk: command execution surface, external package install surface

インストール準備状況

インストールパスを利用可能

  • インストールパスを利用できます
  • リポジトリの根拠を利用できます
  • ライセンスが明示されています
  • Agent-Proven の成果エビデンスはまだありません

Agent 可読メタデータ

このスキルの機械可読な判断データ。

このブロックまたは埋め込み JSON を使い、Agent がこのスキルをインストールすべきか、代替を選ぶべきか、先に人のレビューを求めるべきかを判断できます。

JSON を開く

適したタスク

  • GitHub automation ワークフロー
  • Claude Code チーム
  • GitHub 採用シグナルを重視するチーム
  • Inspect repository metadata

適した Agent

CodexClaude CodeCursorOpenAgentSkill CLIOpenAI AgentsCLI

インストール判断

コマンド
npx skills add samber/cc-skills-golang --skill golang-design-patterns
ポリシー
レビュー
人によるレビュー
はい

信頼とリスク

信頼
70/100
監査
84/100
リスクレベル
要レビュー

成果ループ

エンドポイント
/api/agent/outcome
イベント ID
resolve
成果
5

インストールコマンド

npx skills add samber/cc-skills-golang --skill golang-design-patterns

使わない場合

  • ベンダー提供の SLA が必要なチーム
  • 内部セキュリティレビューのない高コンプライアンス環境
  • 現在のメタデータに重大なリスクシグナルはありません
  • 高リスク権限のヒント: Shell またはコマンド実行
  • Dependency or permission surface needs review

Agent セーフティ v2

52/100 · 自動インストールを避ける

実験的レビュー

Sparse or mixed signals. Useful for discovery, but not for autonomous installation.

Test manually in an isolated workspace and compare against safer alternatives.

API で解決

Shell またはコマンド実行

Skill メタデータに端末、CLI、Shell、サブプロセス、またはコマンド実行のワークフローが含まれます。

ネットワークアクセス

Skill はリモートページ、API、リポジトリ、外部サービスにアクセスする可能性があります。

ファイルシステムアクセス

Skill はプロジェクトファイル、ドキュメント、生成物、ローカルワークスペース状態を読み書きする可能性があります。

データベースアクセス

Skill はスキーマを確認し、データベースを照会し、永続ストアを扱う可能性があります。

  • 高リスク権限のヒント: Shell またはコマンド実行
  • Dependency or permission surface needs review

インストール先

Agent ワークフローにこのスキルをインストール

公開インストールエンドポイントからコマンド、安全チェックリスト、対象プロンプト、正規リンクを取得します。

skill install

OpenAgentSkill CLI

Resolve policy, run the source installer safely, and report a verified install receipt.

$ npx --yes https://github.com/Leon-Drq/openagentskill/releases/download/cli-v0.2.1/openagentskill-0.2.1.tgz install samber-golang-design-patterns

Agent 解決プラン

インストール前に Agent に適合性を検証させます。

Resolve API は第一候補、代替、安全ポリシー、監査メモ、インストール先、Agent がそのまま使えるプロンプトを返します。

テキストプランを開く

Agent が確認すべきこと

  • Resolve API でタスク適合と代替を確認。
  • 監査・信頼スコアと安全ポリシーの警告を確認。
  • Codex、Claude Code、Cursor、CLI のインストール先互換性を確認。

プロンプトをコピー

Task: Use golang-design-patterns in this workspace.
Resolve first: https://www.openagentskill.com/api/agent/resolve?task=Use%20golang-design-patterns%20for%20an%20agent%20workflow&agent=codex&max_risk=medium
Review install handoff: https://www.openagentskill.com/api/skills/samber-golang-design-patterns/install
Install command: npx skills add samber/cc-skills-golang --skill golang-design-patterns
Before running it, summarize audit warnings, required permissions, and the fallback skill if install is risky.

Agent 引き継ぎ

別のディレクトリではなく、インストール経路を Agent に渡します。

公開インストールエンドポイントからコマンド、安全チェックリスト、対象プロンプト、正規リンクを取得します。

Install API を開く

Agent プロンプト

Use golang-design-patterns for this task. Review https://www.openagentskill.com/api/skills/samber-golang-design-patterns/install, then install with: npx skills add samber/cc-skills-golang --skill golang-design-patterns

Registry メタデータ

自動スキル選択用の Agent 可読プロファイル。

Registry API 経由で判断、信頼、監査、ユースケース、インストールのシグナルを提供し、UI をスクレイピングせずに Agent が順位付けできます。

Manifest を開く

Agent 適合

95/100

GitHub automation

プラットフォーム

Claude Code, OpenAI Agents

監査レポート

要レビュー · 84/100

インストール準備、安全メタデータ、保守、採用リスクの機械可読なレビュー。

監査レポートを見る評価レポートを見る

Agent 判断パネル

GitHub automation 向けの第一候補

有力候補として扱い、自分の Agent スタックで README とインストール経路を検証してください。

95
準備状況
採用
段階

スタック内の役割

第一候補

主な適合

GitHub automation

信頼ラベル

本番対応

インストールパス

コマンド準備済み

使う場面

  • GitHub automation ワークフロー
  • Claude Code チーム
  • GitHub 採用シグナルを重視するチーム

根拠

  • GitHub スター 3,022
  • 最近のリポジトリ活動
  • インストールコマンドまたは GitHub リポジトリが利用可能
  • 品質プロファイル 82/100
  • OpenAgentSkill エンゲージメント 4 件

先にレビュー

  • 現在のメタデータに重大なリスクシグナルはありません

実装パス

  1. 1サンドボックスの Agent にインストールし、GitHub automation タスクを一度最初から最後まで実行します。
  2. 2Compare output quality, latency, and failure behavior against at least one alternative.
  3. 3Promote it into production only after reviewing repository permissions, license, and maintenance signals.

信頼プロファイル

サンドボックス限定

信頼シグナルが不足または混在する有用な候補です。結果ループがタスク適合を示すまで、隔離されたワークスペースで使用してください。

70
OpenAgentSkill Trust Score

GitHub 採用度

合格

GitHub スター 3.0K

スター/フォーク活動

情報

スター 3.0K、フォーク 197; 現在のメタデータでは Issue 活動を利用できません

最近のメンテナンス

合格

最終プッシュから 1 日

ライセンスの明確さ

合格

MIT

良いシグナル

  • AI レビュー承認済み
  • インストールパスを利用できます
  • リポジトリの根拠を利用できます
  • 最近保守されたリポジトリ
  • 意味のある GitHub 採用シグナル
  • インストールコマンドに明確な高リスクパターンはありません
  • 成果ループは準備済みですが、最初の実行が必要です

インストール前にレビュー

  • Financial research output is not financial advice; require human review before any live investment decision.
  • Quality score needs review
  • Permission surface needs review: shell or command execution, filesystem or document access
  • Dependency/runtime risk: command execution surface, external package install surface
  • Permission surface: shell or command execution, filesystem or document access
  • 実際の Agent 成果レポートはまだありません
  • 無人インストールの前に人によるレビューが必要です

推奨アクション

実作業で使う前に、サンドボックスでのみ実行し、近い代替と比較してください。

品質プロファイル

強い Agent ワークフロー向けの候補

本番ワークフローの候補に値する堅実な選択肢です。

82
GitHub スター
3.0K
鮮度
1 日前
インストール準備完了
はい
ライセンス
MIT

ワークフロー適合

このスキルを使うシナリオ

ワークフロー適合

完全なワークフローに追加

代替候補

インストール前に比較

このタスクに適する可能性のある類似スキル。

すべて比較

概要

--- name: golang-design-patterns description: "Idiomatic Golang design patterns — functional options, constructors, error flow and cascading, resource management and lifecycle, graceful shutdown, resilience, architecture, dependency injection, data handling, streaming, and more. Apply when explicitly choosing between architectural patterns, implementing functional options, designing constructor APIs, setting up graceful shutdown, applying resilience patterns, or asking which idiomatic Go pattern fits a specific problem." user-invocable: true license: MIT compatibility: Designed for Claude Code, Codex or similar harness, and for projects using Golang. metadata: author: samber version: "1.2.0" openclaw: emoji: "🏗" homepage: https://github.com/samber/cc-skills-golang requires: bins: - go install: [] allowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent AskUserQuestion paths: - "**/*.go" ---

**Persona:** You are a Go architect who values simplicity and explicitness. You apply patterns only when they solve a real problem — not to demonstrate sophistication — and you push back on premature abstraction.

**Modes:**

- **Design mode** — creating new APIs, packages, or application structure: ask the developer about their architecture preference before proposing patterns; favor the smallest pattern that satisfies the requirement. - **Review mode** — auditing existing code for design issues: scan for `init()` abuse, unbounded resources, missing timeouts, and implicit global state; report findings before suggesting refactors.

> **Community default.** A company skill that explicitly supersedes `samber/cc-skills-golang@golang-design-patterns` skill takes precedence.

# Go Design Patterns & Idioms

Idiomatic Go patterns for production-ready code. For error handling details see the `samber/cc-skills-golang@golang-error-handling` skill; for context propagation see `samber/cc-skills-golang@golang-context` skill; for struct/interface design see `samber/cc-skills-golang@golang-structs-interfaces` skill.

## Best Practices Summary

1. Constructors SHOULD use **functional options** — they scale better as APIs evolve (one function per option, no breaking changes) 2. Functional options MUST **return an error** if validation can fail — catch bad config at construction, not at runtime 3. **Avoid `init()`** — runs implicitly, cannot return errors, makes testing unpredictable. Use explicit constructors 4. Enums SHOULD **start at 1** (or Unknown sentinel at 0) — Go's zero value silently passes as the first enum member 5. Error cases MUST be **handled first** with early return — keep happy path flat 6. **Panic is for bugs, not expected errors** — callers can handle returned errors; panics crash the process 7. **`defer Close()` immediately after opening** — later code changes can accidentally skip cleanup 8. **`runtime.AddCleanup`** over `runtime.SetFinalizer` — finalizers are unpredictable and can resurrect objects 9. Every external call SHOULD **have a timeout** — a slow upstream hangs your goroutine indefinitely 10. **Limit everything** (pool sizes, queue depths, buffers) — unbounded resources grow until they crash 11. Retry logic MUST **check context cancellation** between attempts 12. **Use `strings.Builder`** for concatenation in loops → see `samber/cc-skills-golang@golang-code-style` 13. string vs []byte: **use `[]byte` for mutation and I/O**, `string` for display and keys — conversions allocate 14. Iterators (Go 1.23+): **use for lazy evaluation** — avoid loading everything into memory 15. **Stream large transfers** — loading millions of rows causes OOM; stream keeps memory constant 16. `//go:embed` for **static assets** — embeds at compile time, eliminates runtime file I/O errors 17. **Use `crypto/rand`** for keys/tokens — `math/rand` is predictable → see `samber/cc-skills-golang@golang-security` 18. Regexp MUST be **compiled once at package level** — compilation is O(n) and allocates 19. Compile-time interface checks: **`var _ Interface = (*Type)(nil)`** 20. **A little recode > a big dependency** — each dep adds attack surface and maintenance burden 21. **Design for testability** — accept interfaces, inject dependencies

## Constructor Patterns: Functional Options vs Builder

### Functional Options (Preferred)

```go type Server struct { addr string readTimeout time.Duration writeTimeout time.Duration maxConns int }

type Option func(*Server)

func WithReadTimeout(d time.Duration) Option { return func(s *Server) { s.readTimeout = d } }

func WithWriteTimeout(d time.Duration) Option { return func(s *Server) { s.writeTimeout = d } }

func WithMaxConns(n int) Option { return func(s *Server) { s.maxConns = n } }

func NewServer(addr string, opts ...Option) *Server { // Default options s := &Server{ addr: addr, readTimeout: 5 * time.Second, writeTimeout: 10 * time.Second, maxConns: 100, } for _, opt := range opts { opt(s) } return s }

// Usage srv := NewServer(":8080", WithReadTimeout(30*time.Second), WithMaxConns(500), ) ```

Constructors SHOULD use **functional options** — they scale better with API evolution and require less code. Use builder pattern only if you need complex validation between configuration steps.

## Constructors & Initialization

### Avoid `init()` and Mutable Globals

`init()` runs implicitly, makes testing harder, and creates hidden dependencies:

- Multiple `init()` functions run in declaration order, across files in **filename alphabetical order** — fragile - Cannot return errors — failures must panic or `log.Fatal` - Runs before `main()` and tests — side effects make tests unpredictable

```go // Bad — hidden global state var db *sql.DB

func init() { var err error db, err = sql.Open("postgres", os.Getenv("DATABASE_URL")) if err != nil { log.Fatal(err) } }

// Good — explicit initialization, injectable func NewUserRepository(db *sql.DB) *UserRepository { return &UserRepository{db: db} } ```

### Enums: Start at 1

Zero values should represent invalid/unset state:

```go type Status int

const ( StatusUnknown Status = iota // 0 = invalid/unset StatusActive // 1 StatusInactive // 2 StatusSuspended // 3 ) ```

### Compile Regexp Once

```go // Good — compiled once at package level var emailRegex = regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)

func ValidateEmail(email string) bool { return emailRegex.MatchString(email) } ```

### Use `//go:embed` for Static Assets

```go import "embed"

//go:embed templates/* var templateFS embed.FS

//go:embed version.txt var version string ```

### Compile-Time Interface Checks

→ See `samber/cc-skills-golang@golang-structs-interfaces` for the `var _ Interface = (*Type)(nil)` pattern.

## Error Flow Patterns

Error cases MUST be handled first with early return — keep the happy path at minimal indentation. → See `samber/cc-skills-golang@golang-code-style` for the full pattern and examples.

### When to Panic vs Return Error

- **Return error**: network failures, file not found, invalid input — anything a caller can handle - **Panic**: nil pointer in a place that should be impossible, violated invariant, `Must*` constructors used at init time - **`.Close()` / `Flush()` errors**: read-only cleanup can often use `defer f.Close()`, but write/flush resources must report close or flush errors when durability matters

## Data Handling

### string vs []byte vs []rune

| Type | Default for | Use when | | -------- | ----------- | --------------------------------------------------- | | `string` | Everything | Immutable, safe, UTF-8 | | `[]byte` | I/O | Writing to `io.Writer`, building strings, mutations | | `[]rune` | Unicode ops | `len()` must mean characters, not bytes |

Avoid repeated conversions — each one allocates. Stay in one type until you need the other.

### Iterators & Streaming for Large Data

Use iterators (Go 1.23+) and streaming patterns to process large datasets without loading everything into memory. For large transfers between services (e.g., 1M rows DB to HTTP), stream to prevent OOM.

For code examples, see [Data Handling Patterns](references/data-handling.md).

## Resource Management

`defer Close()` immediately after opening — don't wait, don't forget:

```go f, err := os.Open(path) if err != nil { return err } defer f.Close() // right here, not 50 lines later

rows, err := db.QueryContext(ctx, query) if err != nil { return err } defer rows.Close() ```

For graceful shutdown, resource pools, and `runtime.AddCleanup`, see [Resource Management](references/resource-management.md).

## Resilience & Limits

### Timeout Every External Call

```go ctx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel()

resp, err := httpClient.Do(req.WithContext(ctx)) ```

### Retry & Context Checks

Retry logic MUST check `ctx.Err()` between attempts and use exponential/linear backoff via `select` on `ctx.Done()`. Long loops MUST check `ctx.Err()` periodically. → See `samber/cc-skills-golang@golang-context` skill.

## Database Patterns

→ See `samber/cc-skills-golang@golang-database` skill for sqlx/pgx, transactions, nullable columns, connection pools, repository interfaces, testing.

## Architecture

Ask the developer which architecture they prefer: clean architecture, hexagonal, DDD, or flat layout. Don't impose complex architecture on a small project.

Core principles regardless of architecture:

- **Keep domain pure** — no framework dependencies in the domain layer - **Fail fast** — validate at boundaries, trust internal code - **Make illegal states unrepresentable** — use types to enforce invariants - **Respect 12-factor app** principles — → see `samber/cc-skills-golang@golang-project-layout`

## Detailed Guides

| Guide | Scope | | --- | --- | | [Architecture Patterns](references/architecture.md) | High-level principles, when each architecture fits | | [Clean Architecture](references/clean-architecture.md) | Use cases, dependency rule, layered adapters | | [Hexagonal Architecture](references/hexagonal-architecture.md) | Ports and adapters, domain core isolation | | [Domain-Driven Design](references/ddd.md) | Aggregates, value objects, bounded contexts |

## Code Philosophy

- **Avoid repetitive code** — but don't abstract prematurely - **Minimize dependencies** — a little recode > a big dependency - **Design for testability** — accept interfaces, inject dependencies, keep functions pure

## Cross-References

- → See `samber/cc-skills-golang@golang-data-structures` skill for data structure selection, internals, and container/ packages - → See `samber/cc-skills-golang@golang-error-handling` skill for error wrapping, sentinel errors, and the single handling rule - → See `samber/cc-skills-golang@golang-structs-interfaces` skill for interface design and composition - → See `samber/cc-skills-golang@golang-concurrency` skill for goroutine lifecycle and graceful shutdown - → See `samber/cc-skills-golang@golang-context` skill for timeout and cancellation patterns - → See `samber/cc-skills-golang@golang-project-layout` skill for architecture and directory structure - → See `samber/cc-skills-golang@golang-refactoring` skill for safely staging a migration toward one of these patterns (options struct, DI, consumer-side interfaces) across an existing codebase

技術詳細

バージョン
1.0.0
ライセンス
MIT
最終更新
2026年8月21日
公開日
2026年8月21日

判断の要約

第一候補

95
準備完了
採用
段階

GitHub スター 3,022

監査

インストールレビュー

インストールと採用のレビュー

84
要レビュー
セキュリティ
78/100
メンテナンス
100/100
インストール
92/100
完全な監査を開く評価レポートを見る

Agent 実証エビデンス

Agent 実証エビデンス

Resolve、レビュー、インストール、限定実行後の成果レポート。

0
実証済み
Needs first agent run自動インストール: 先にレビュー最新: 不明
成功率
直近の失敗
成果
0
出力品質
失敗
0
非該当
0
インストール数
0
リスクによりブロック
0
設定が必要
0
本番
0

Agent の実行結果はまだありません。最初の実行では /api/agent/outcome を通じて成功、設定要件、リスクによるブロック、失敗、非該当を報告できます。

インストール

Agent ワークフローに追加

無料・オープンソース. 本番 Agent にインストールする前にレポートを確認してください。

成長ループ

共有キット

X

golang-design-patterns 用のシナリオベース草案です。X へ手動投稿できます。

キュレーターノート
golang-design-patterns: Idiomatic Golang design patterns — functional options, constructors, error flow and cascading...

3.0K stars

https://www.openagentskill.com/skills/samber-golang-design-patterns?ref=x
X 下書きを開く
任意:インストールコマンド付きの返信
Listing + install path for golang-design-patterns:
https://www.openagentskill.com/skills/samber-golang-design-patterns?ref=x

Install: npx skills add samber/cc-skills-golang --skill golang-design-patterns
返信の下書きを開く

掲載元

Registry により登録

申請可能

この掲載は公開ソースから登録されており、メンテナー申請が承認されるまで公式として表示されません。

作成者
samber
インデックス作成者
OpenAgentSkill コミュニティインデックス

帰属は公開リポジトリまたは作成者プロフィールにリンクされています。作成者は掲載を申請して所有権シグナルを更新できます。

このスキルを申請

所有者の申請

このスキル掲載を申請

この Registry により登録 掲載は samber に帰属していますが、まだ公式として表示されていません。申請すると、確認済み所有者シグナルが追加され、今後の公開、インストール、監査更新の信頼性が高まります。

クリエイター被リンクキット

README にエビデンスバッジを追加

開発者がリポジトリを評価する場所で、正規掲載、現在の信頼・監査シグナル、実際の Agent-Proven エビデンスを表示します。

[![Listed on OpenAgentSkill](https://www.openagentskill.com/api/badge/samber-golang-design-patterns?metric=listed&label=Listed)](https://www.openagentskill.com/skills/samber-golang-design-patterns)
[![OpenAgentSkill Trust](https://www.openagentskill.com/api/badge/samber-golang-design-patterns?metric=trust&label=Trust)](https://www.openagentskill.com/skills/samber-golang-design-patterns)
[![OpenAgentSkill Audit](https://www.openagentskill.com/api/badge/samber-golang-design-patterns?metric=audit&label=Audit)](https://www.openagentskill.com/skills/samber-golang-design-patterns/audit)
[![Agent Proven](https://www.openagentskill.com/api/badge/samber-golang-design-patterns?metric=proven&label=Agent%20Proven)](https://www.openagentskill.com/skills/samber-golang-design-patterns)

作者

S

samber

@samber

プラットフォーム適合

健全性シグナル

GitHub スター
3.0K
品質スコア
48/100
最終 GitHub プッシュ
2026年8月21日
フレームワークのヒント
不明
OpenAgentSkill 閲覧数
4
インストールコピー数
0
外部クリック
0

コミュニティシグナル

このスキルが Agent ワークフローに役立つかを共有してください。集約されたフィードバックがランキングを改善します。

信頼と安全性

サンドボックス限定

70
  • GitHub 採用度GitHub スター 3.0K合格
  • スター/フォーク活動スター 3.0K、フォーク 197; 現在のメタデータでは Issue 活動を利用できません情報
  • 最近のメンテナンス最終プッシュから 1 日合格
  • ライセンスの明確さMIT合格
  • README/SKILL.md の完全性メタデータには十分な利用・ワークフロー文脈があります合格
  • 依存関係/ランタイムのリスクcommand execution surface, external package install surface確認