ホーム/技术写作/go-documentation
G

go-documentation

by @cxuuv
4.6(39)

Go言語パッケージのドキュメント作成またはレビューに使用され、その明確さと正確性を保証します。

Go DocumentationTechnical WritingGodocAPI DocumentationGitHub
インストール方法
npx skills add cxuu/golang-skills --skill go-documentation
compare_arrows

Before / After 効果比較

1
使用前

以前は、Go言語のパッケージドキュメントが不完全で、新しい開発者が関数の使い方を理解するのが難しく、統合時にエラーが頻発し、試行錯誤に多くの時間を費やしていました。

使用後

現在、Goのドキュメントは明確かつ正確で、各パッケージの機能と使用法が詳細に説明されており、学習コストを大幅に削減し、開発効率を向上させています。

description SKILL.md


name: go-documentation description: Use when writing or reviewing documentation for Go packages, types, functions, or methods. Also use proactively when creating new exported types, functions, or packages, even if the user doesn't explicitly ask about documentation. Does not cover code comments for non-exported symbols (see go-style-core). license: Apache-2.0 metadata: sources: "Google Style Guide" allowed-tools: Bash(bash:*)

Go Documentation

Available Scripts

  • scripts/check-docs.sh — Reports exported functions, types, methods, constants, and packages missing doc comments. Run bash scripts/check-docs.sh --help for options.

See assets/doc-template.go when writing doc comments for a new package or exported type and need a complete reference of all documentation conventions.


Doc Comments

Normative: All top-level exported names must have doc comments.

Basic Rules

  1. Begin with the name of the object being described
  2. An article ("a", "an", "the") may precede the name
  3. Use full sentences (capitalized, punctuated)
// A Request represents a request to run a command.
type Request struct { ...

// Encode writes the JSON encoding of req to w.
func Encode(w io.Writer, req *Request) { ...

Unexported types/functions with unobvious behavior should also have doc comments.

Validation: After adding doc comments, run bash scripts/check-docs.sh to verify no exported symbols are missing documentation. Fix any gaps before proceeding.


Comment Sentences

Normative: Documentation comments must be complete sentences.

  • Capitalize the first word, end with punctuation
  • Exception: may begin with uncapitalized identifier if clear
  • End-of-line comments for struct fields can be phrases

Comment Line Length

Advisory: Aim for ~80 columns, but no hard limit.

Break based on punctuation. Don't split long URLs.


Struct Documentation

Group fields with section comments. Mark optional fields with defaults:

type Options struct {
    // General setup:
    Name  string
    Group *FooGroup

    // Customization:
    LargeGroupThreshold int // optional; default: 10
}

Package Comments

Normative: Every package must have exactly one package comment.

// Package math provides basic constants and mathematical functions.
package math
  • For main packages, use the binary name: // The seed_generator command ...
  • For long package comments, use a doc.go file

Read references/EXAMPLES.md when writing package-level docs, main package comments, doc.go files, or runnable examples.


What to Document

Advisory: Document non-obvious behavior, not obvious behavior.

TopicDocument when...Skip when...
ParametersNon-obvious behavior, edge casesRestates the type signature
ContextsBehavior differs from standard cancellationStandard ctx.Err() return
ConcurrencyAmbiguous thread safety (e.g., read that mutates)Read-only is safe, mutation is unsafe
CleanupAlways document resource release
ErrorsSentinel values, error types (use *PathError)
Named resultsMultiple params of same type, action-oriented namesType alone is clear enough

Key principles:

  • Context cancellation returning ctx.Err() is implied — don't restate it
  • Read-only ops are assumed thread-safe; mutations assumed unsafe — don't restate
  • Always document cleanup requirements (e.g., Call Stop to release resources)
  • Use pointer in error type docs (*PathError) for correct errors.Is/errors.As
  • Don't name results just to enable naked returns — clarity > brevity

Read references/CONVENTIONS.md when documenting parameter behavior, context cancellation, concurrency safety, cleanup requirements, error returns, or named result parameters in function doc comments.


Runnable Examples

Advisory: Provide runnable examples in test files (*_test.go).

func ExampleConfig_WriteTo() {
    cfg := &Config{Name: "example"}
    cfg.WriteTo(os.Stdout)
    // Output:
    // {"name": "example"}
}

Examples appear in Godoc attached to the documented element.

Read references/EXAMPLES.md when writing runnable Example functions, choosing example naming conventions (Example vs ExampleType_Method), or adding package-level doc.go files.


Godoc Formatting

Read references/FORMATTING.md when formatting godoc headings, links, lists, or code blocks, using signal boosting for deprecation notices, or previewing doc output locally.


Quick Reference

TopicKey Rule
Doc commentsStart with name, use full sentences
Line length~80 chars, prioritize readability
Package commentsOne per package, above package clause
ParametersDocument non-obvious behavior only
ContextsDocument exceptions to implied behavior
ConcurrencyDocument ambiguous thread safety
CleanupAlways document resource release
ErrorsDocument sentinels and types (note pointer)
ExamplesUse runnable examples in test files
FormattingBlank lines for paragraphs, indent for code

Related Skills

  • Naming conventions: See go-naming when choosing names for the identifiers your doc comments describe
  • Testing examples: See go-testing when writing runnable Example test functions that appear in godoc
  • Linting enforcement: See go-linting when using revive or other linters to enforce doc comment presence
  • Style principles: See go-style-core when balancing documentation verbosity against clarity and concision

forumユーザーレビュー (0)

レビューを書く

効果
使いやすさ
ドキュメント
互換性

レビューなし

統計データ

インストール数1.5K
評価4.6 / 5.0
バージョン
更新日2026年3月17日
比較事例1 件

ユーザー評価

4.6(39)
5
0%
4
0%
3
0%
2
0%
1
0%

この Skill を評価

0.0

対応プラットフォーム

🔧Claude Code
🔧OpenClaw
🔧OpenCode
🔧Codex
🔧Gemini CLI
🔧GitHub Copilot
🔧Amp
🔧Kimi CLI

タイムライン

作成2026年3月17日
最終更新2026年3月17日