go-documentation

cxuu/golang-skills · updated Apr 8, 2026

$npx skills add https://github.com/cxuu/golang-skills --skill go-documentation
0 commentsdiscussion
summary

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.

skill.md

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.

Topic Document when... Skip when...
Parameters Non-obvious behavior, edge cases Restates the type signature
Contexts Behavior differs from standard cancellation Standard ctx.Err() return
Concurrency Ambiguous thread safety (e.g., read that mutates) Read-only is safe, mutation is unsafe
Cleanup Always document resource release
Errors Sentinel values, error types (use *PathError)
Named results Multiple params of same type, action-oriented names Type 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

Topic Key Rule
Doc comments Start with name, use full sentences
Line length ~80 chars, prioritize readability
Package comments One per package, above package clause
Parameters Document non-obvious behavior only
Contexts Document exceptions to implied behavior
Concurrency Document ambiguous thread safety
Cleanup Always document resource release
Errors Document sentinels and types (note pointer)
Examples Use runnable examples in test files
Formatting Blank 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

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.737 reviews
  • Valentina Li· Dec 28, 2024

    We added go-documentation from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

  • Shikha Mishra· Dec 24, 2024

    go-documentation is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Omar Park· Dec 8, 2024

    go-documentation fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Valentina Mensah· Dec 4, 2024

    Registry listing for go-documentation matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Nia Sanchez· Nov 27, 2024

    I recommend go-documentation for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Amelia Nasser· Nov 23, 2024

    go-documentation reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Yash Thakker· Nov 15, 2024

    Useful defaults in go-documentation — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Carlos Jackson· Oct 18, 2024

    Solid pick for teams standardizing on skills: go-documentation is focused, and the summary matches what you get after install.

  • Soo Smith· Oct 14, 2024

    go-documentation is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Dhruvi Jain· Oct 6, 2024

    Registry listing for go-documentation matched our evaluation — installs cleanly and behaves as described in the markdown.

showing 1-10 of 37

1 / 4