← All notes

Go go/doc: extract documentation from a Go syntax tree

Answer: Package doc extracts source code documentation from a Go AST.

What the package builds

Package doc reads documentation out of a Go AST.

A Package value holds documentation for an entire package.

Type and Func values hold documentation for type and function declarations, and Value covers a var or const declaration.

Examples is a sorted list of examples associated with the package, extracted from _test.go files.

For backward compatibility, Bugs is still populated, but all new code should use Notes instead.

Comments and older helpers

IllegalPrefixes lists lower-case prefixes such as copyright, all rights, and author that mark a comment as not a doc comment.

That list helps avoid treating a copyright notice just before a package statement as package documentation.

IsPredeclared reports whether a string is a predeclared identifier.

Synopsis, ToHTML, and ToText are deprecated because they cannot identify documentation links without knowing the package the text came from.

New programs should use Package.Synopsis instead, which handles links properly.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, go/doc; The Go Authors, go/doc source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Go Authors, go/doc; The Go Authors, go/doc source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.

Cite this

Permanent ID: iil:note:qy0gk6cf

iinventedlight. 2026. "Go go/doc: extract documentation from a Go syntax tree." iinventedlight Library, iil:note:qy0gk6cf, version of 2026-11-26. https://iinventedlight.com/library/notes/go-doc/. License: CC-BY-4.0.

@misc{iil_note_qy0gk6cf,
  author = {{iinventedlight}},
  title = {{Go go/doc: extract documentation from a Go syntax tree}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-26},
  url = {https://iinventedlight.com/library/notes/go-doc/},
  note = {Permanent ID iil:note:qy0gk6cf. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-doc.md.