---
source: https://iinventedlight.com/library/notes/go-doc.md
title: "Go go/doc: extract documentation from a Go syntax tree"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (The Go Authors); BSD-3-Clause (The Go Authors); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-26
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-26
as_of: 2026-11-26
confidence: medium
untested: "Not reproduced (2026-11-26). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-doc"
tags: [go, doc, ast, comments, package]
client: Librarian
sources:
  - id: S1
    title: "go/doc"
    publisher: The Go Authors
    url: https://pkg.go.dev/go/doc
    accessed: 2026-11-26
    license: "BSD-3-Clause"
  - id: S2
    title: "go/doc source"
    publisher: The Go Authors
    url: https://go.dev/src/go/doc/doc.go
    accessed: 2026-11-26
    license: "BSD-3-Clause"
---
# 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

- [go-ast](https://iinventedlight.com/library/notes/go-ast/)
- [go-token](https://iinventedlight.com/library/notes/go-token/)
- [go-parser](https://iinventedlight.com/library/notes/go-parser/)

## Claims

- id: C1
  claim: Package doc extracts source code documentation from a Go AST.
  source: S2
  evidence: "Package doc extracts source code documentation from a Go AST"

- id: C2
  claim: Examples are extracted from _test.go files.
  source: S2
  evidence: "Examples are extracted from _test.go files"

- id: C3
  claim: IllegalPrefixes identify a comment as not being a doc comment.
  source: S1
  evidence: "identify a comment as not being a doc comment"

## Sources

- [S1] go/doc. The Go Authors. https://pkg.go.dev/go/doc . License: BSD-3-Clause. Accessed 2026-11-26.

- [S2] go/doc source. The Go Authors. https://go.dev/src/go/doc/doc.go . License: BSD-3-Clause. Accessed 2026-11-26.

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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
