Skip to content
go-doc logo

Go Doc Comments

go-doc

This skill should be used when drafting or reviewing Go doc comments so they align with the official Go documentation style and pkgsite rendering rules.

SKILL.md

Full skill instructions

Go Doc Comments

Overview

Produce doc comments that render cleanly in go doc, pkgsite, and IDEs by following the Go project's official guidance. Apply this skill whenever documenting exported Go identifiers or packages.

When to Use

  • Document exported Go packages, commands, types, funcs, consts, or vars.
  • Review existing comments for compliance during code review or refactors.
  • Convert informal inline comments into doc comments intended for pkgsite.

Avoid invoking this skill for unexported identifiers unless the repository mandates internal documentation parity.

Workflow

  1. Locate the target declaration
    Place the comment immediately above the top-level declaration with no blank lines between the comment and the declaration.

  2. Draft the lead sentence

    • Start package comments with Package <name> ... in complete sentences.
    • Start command package comments with the capitalized program name, e.g., Gofmt formats Go programs.
    • Start other doc comments with the identifier name followed by a verb phrase that explains what it does (e.g., Serve starts an HTTP server.).
  3. Expand the description

    • Describe behavior, usage, and key arguments succinctly.
    • Link to related APIs using square brackets ([net/​http]) so pkgsite creates hyperlinks.
    • Use semantic linefeeds (one sentence per line) when it improves diffs; pkgsite rewraps automatically.
  4. Format structured content

    • Indent lists and code blocks with either a tab or two spaces so they render correctly.
    • Create numbered or bulleted lists with a leading tab/​space and a marker (- or digits).
    • Avoid nested lists; rewrite as multiple paragraphs or mixed markers if hierarchy is essential.
    • Indent multi-line shell commands or code samples consistently, and add blank lines before and after blocks.
  5. Preserve tone and accuracy

    • Use present tense and active voice.
    • Keep comments factual; avoid marketing language.
    • Mention exported error conditions, side effects, and concurrency guarantees as needed.
  6. Validate rendering

    • Run go doc <pkg>.<Symbol> or view via pkgsite to confirm wrapping, lists, and links render as expected.
    • Run gofmt (Go 1.19+) to ensure indentation aligns with the doc-comment heuristics.
    • Adjust spacing if gofmt highlights ambiguous paragraphs (add or remove blank lines).

Quick Checklist

  • Begin with the correct identifier prefix (Package, symbol name, or command).
  • Keep sentences complete and punctuated.
  • Use links [package] or [Type.Method] for cross references.
  • Indent lists, code blocks, and shell snippets.
  • Avoid nested lists; restructure instead.
  • Verify formatting with go doc and gofmt.

Good and Bad Examples

Good – Package comment introducing scope and linking APIs

// Package cache provides in-memory caches with automatic eviction policies.
//
// The package exposes [LRU] and [TTL] caches that guard concurrent access with
// sync.RWMutex. Use [NewLRU] for bounded caches and [NewTTL] when entries expire
// after a fixed duration.
package cache

Why it works:

  • Opens with Package cache.
  • Summarises primary types and cross-links constructors.
  • Uses short sentences and a blank line for readability.

Bad – Missing identifier prefix and malformed list

// Provides caches that can evict entries.
// - LRU policy
// - TTL policy
package cache

Issues:

  • First sentence omits the Package prefix, so the synopsis becomes unclear.
  • List items are unindented, so pkgsite renders them as plain text.
  • Does not explain when to choose each policy.

Good – Function comment covering behavior and errors

// Fetch retrieves the value for key from the remote store.
//
// Fetch retries transient failures using exponential backoff and returns an
// error that implements [net.Error] when the deadline expires.
func Fetch(ctx context.Context, key string) ([]byte, error) {

Highlights:

  • Begins with the function name.
  • Documents retry policy and exported error semantics.
  • Uses semantic linefeeds to keep diffs focused on changed sentences.

Bad – Narrative tone and misleading code block

// This function is going to try to get your data, but it might fail!!
// If it fails we waited too long and the store is DEAD.
//    retryCount++
func Fetch(ctx context.Context, key string) ([]byte, error) {

Problems:

  • Uses second-person narrative and emotional language.
  • Fails to mention the function name or concrete behavior.
  • Indented retryCount++ is treated as a code block even though it provides no context.

Validation Tools

  • go doc <package> or go doc <package>.<Symbol> – preview rendered documentation.
  • pkgsite (local or hosted) – inspect pkgsite rendering.
  • gofmt – verify indentation heuristics for doc comments.

Quick Checklist

  • Comment sits immediately above the exported declaration with no blank line.
  • Lead sentence starts with Package, the program name, or the symbol name.
  • Sentences are complete, factual, and written in present tense.
  • Links use square brackets ([pkg.Symbol]) to enable pkgsite cross references.
  • Lists and code snippets are indented; nested lists are avoided.
  • Error contracts, side effects, and concurrency guarantees are documented.
  • go doc preview looks correct and gofmt leaves formatting untouched.

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View