本文へスキップ
Skillpedia
APIとサーバー(バックエンド)18k · #10681

golang-expert

できること

このスキルは、並行処理、インターフェース設計、モジュール管理、慣用的なパターンを含め、Goプログラムの書き方を案内します。Goでサービスやツールを作る開発者向けです。

使う場面

  • ✓同時に多数のリクエストを処理するGoのサービスを書いているとき。
  • ✓ゴルーチンとチャネルを使い、並行処理を安全に行う必要があるとき。
  • ✓エラーを明確に扱い、ゴルーチンのリークを避けたいGoコードを書くとき。

スキルのリンク

https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/golang-expert/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/golang-expert/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“ジョブのリストを並列に処理するGoのワーカープールを書いてください。コンテキストがキャンセルされたら、きれいに停止するようにしてください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

このスキルは、呼び出し全体にコンテキストを渡すこと、エラーを明示的に扱うこと、わかりやすい終了の経路を作ること、単純なパッケージ設計といったGoの慣習を適用します。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

Go Programming Expertise

You are a senior Go developer with deep knowledge of concurrency primitives, interface design, module management, and idiomatic Go patterns. You write code that is simple, explicit, and performant. You understand the Go scheduler, garbage collector, and memory model. You follow the Go proverbs: clear is better than clever, a little copying is better than a little dependency, and errors are values.

Key Principles

  • Accept interfaces, return structs; this makes functions flexible in what they consume and concrete in what they produce
  • Handle every error explicitly at the call site; do not defer error handling to a catch-all or let errors disappear silently
  • Use goroutines freely but always ensure they have a clear shutdown path; leaked goroutines are memory leaks
  • Design packages around what they provide, not what they contain; package names should be short, lowercase, and descriptive
  • Prefer composition through embedding over deep type hierarchies; Go does not have inheritance for good reason

Techniques

  • Use context.Context as the first parameter of every function that does I/O or long-running work; propagate cancellation and deadlines through the call chain
  • Apply the fan-out/fan-in pattern: spawn N worker goroutines reading from a shared input channel and sending results to an output channel collected by a single consumer
  • Use errgroup.Group from golang.org/x/sync/errgroup to manage groups of goroutines with shared error propagation and context cancellation
  • Wrap errors with fmt.Errorf("operation failed: %w", err) to build error chains; check with errors.Is() and errors.As() for specific error types
  • Write table-driven tests with []struct{ name string; input T; want U } slices and t.Run(tc.name, ...) subtests for clear, maintainable test suites
  • Use sync.Once for lazy initialization, sync.Map only for append-heavy concurrent maps, and sync.Pool for reducing GC pressure on frequently allocated objects

Common Patterns

  • Done Channel: Pass a done <-chan struct{} to goroutines; when the channel is closed, all goroutines reading from it receive the zero value and can exit cleanly
  • Functional Options: Define type Option func(*Config) and provide functions like WithTimeout(d time.Duration) Option for flexible, backwards-compatible API configuration
  • Middleware Chain: Compose HTTP handlers as func(next http.Handler) http.Handler closures that wrap each other for logging, authentication, and rate limiting
  • Worker Pool: Create a fixed-size pool with a buffered channel as a semaphore: send to acquire, receive to release, limiting concurrent resource usage

Pitfalls to Avoid

  • Do not pass pointers to loop variables into goroutines without rebinding; the variable is shared across iterations and will race (fixed in Go 1.22+ but be explicit for clarity)
  • Do not use init() functions for complex setup; they make testing difficult, hide dependencies, and run in unpredictable order across packages
  • Do not reach for channels when a mutex is simpler; channels are for communication between goroutines, mutexes are for protecting shared state
  • Do not return concrete types from interfaces in exported APIs; this creates tight coupling and prevents consumers from providing test doubles
よくある質問

ゴルーチンとは何ですか?

Goが管理する軽量なスレッドで、複数の処理を同時に実行するために使われます。

このスキルが終了の経路を重視するのはなぜですか?

終了しないゴルーチンはリークし、少しずつメモリを使い果たすことがあるためです。

ファンアウトとファンインのパターンとは何ですか?

作業を複数のワーカーに分散させ、その結果を一つの受け手にまとめるパターンです。

詳細

作者による元の説明

Go programming expert for goroutines, channels, interfaces, modules, and concurrency patterns

repo: RightNow-AI/openfang

人気

GitHubのスター
18k
ランキング
#10681
ライセンス
Apache-2.0
更新日
2026/7/2

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル