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.
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.
Avoid invoking this skill for unexported identifiers unless the repository mandates internal documentation parity.
Locate the target declaration
Place the comment immediately above the top-level declaration with no blank lines between the comment and the declaration.
Draft the lead sentence
Package <name> ... in complete sentences. Gofmt formats Go programs. Serve starts an HTTP server.).Expand the description
[net/http]) so pkgsite creates hyperlinks. Format structured content
- or digits). Preserve tone and accuracy
Validate rendering
go doc <pkg>.<Symbol> or view via pkgsite to confirm wrapping, lists, and links render as expected. gofmt (Go 1.19+) to ensure indentation aligns with the doc-comment heuristics. Package, symbol name, or command). [package] or [Type.Method] for cross references. go doc and gofmt.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:
Package cache.Bad – Missing identifier prefix and malformed list
// Provides caches that can evict entries.
// - LRU policy
// - TTL policy
package cache
Issues:
Package prefix, so the synopsis becomes unclear.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:
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:
retryCount++ is treated as a code block even though it provides
no context.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.Package, the program name, or the symbol name.[pkg.Symbol]) to enable pkgsite cross references.go doc preview looks correct and gofmt leaves formatting untouched.