package doc

Import Path
	go/doc (on golang.org and go.dev)

Dependency Relation
	imports 13 packages, and imported by one package

Involved Source Files
	    comment.go
	d-> doc.go
	    example.go
	    exports.go
	    filter.go
	    reader.go
	    synopsis.go

Exported Type Names

type Example (struct) An Example represents an example function found in a test source file. Code ast.Node Comments []*ast.CommentGroup Doc string EmptyOutput bool Name string Order int Output string Play *ast.File Suffix string Unordered bool func Examples(testFiles ...*ast.File) []*Example
type Filter (func) func (*Package).Filter(f Filter)
type Func (struct) Func is the documentation for a func declaration. Decl *ast.FuncDecl Doc string Examples []*Example Level int Name string Orig string Recv string
type Mode int Mode values control the operation of New and NewFromFiles. func New(pkg *ast.Package, importPath string, mode Mode) *Package const AllDecls const AllMethods const PreserveAST
type Note (struct) A Note represents a marked comment starting with "MARKER(uid): note body". Any note with a marker of 2 or more upper case [A-Z] letters and a uid of at least one character is recognized. The ":" following the uid is optional. Notes are collected in the Package.Notes map indexed by the notes marker. Body string End token.Pos Pos token.Pos UID string
type Package (struct) Package is the documentation for an entire package. Bugs []string Consts []*Value Doc string Examples []*Example Filenames []string Funcs []*Func ImportPath string Imports []string Name string Notes map[string][]*Note Types []*Type Vars []*Value (*T) Filter(f Filter) func New(pkg *ast.Package, importPath string, mode Mode) *Package func NewFromFiles(fset *token.FileSet, files []*ast.File, importPath string, opts ...interface{}) (*Package, error)
type Type (struct) Type is the documentation for a type declaration. Consts []*Value Decl *ast.GenDecl Doc string Examples []*Example Funcs []*Func Methods []*Func Name string Vars []*Value
type Value (struct) Value is the documentation for a (possibly grouped) var or const declaration. Decl *ast.GenDecl Doc string Names []string
Exported Values
const AllDecls Mode = 1 AllDecls says to extract documentation for all package-level declarations, not just exported ones.
const AllMethods Mode = 2 AllMethods says to show all embedded methods, not just the ones of invisible (unexported) anonymous fields.
func Examples(testFiles ...*ast.File) []*Example Examples returns the examples found in testFiles, sorted by Name field. The Order fields record the order in which the examples were encountered. The Suffix field is not populated when Examples is called directly, it is only populated by NewFromFiles for examples it finds in _test.go files. Playable Examples must be in a package whose name ends in "_test". An Example is "playable" (the Play field is non-nil) in either of these circumstances: - The example function is self-contained: the function references only identifiers from other packages (or predeclared identifiers, such as "int") and the test file does not include a dot import. - The entire test file is the example: the file contains exactly one example function, zero test or benchmark functions, and at least one top-level function, type, variable, or constant declaration other than the example function.
func IsPredeclared(s string) bool IsPredeclared reports whether s is a predeclared identifier.
func New(pkg *ast.Package, importPath string, mode Mode) *Package New computes the package documentation for the given package AST. New takes ownership of the AST pkg and may edit or overwrite it. To have the Examples fields populated, use NewFromFiles and include the package's _test.go files.
func NewFromFiles(fset *token.FileSet, files []*ast.File, importPath string, opts ...interface{}) (*Package, error) NewFromFiles computes documentation for a package. The package is specified by a list of *ast.Files and corresponding file set, which must not be nil. NewFromFiles uses all provided files when computing documentation, so it is the caller's responsibility to provide only the files that match the desired build context. "go/build".Context.MatchFile can be used for determining whether a file matches a build context with the desired GOOS and GOARCH values, and other build constraints. The import path of the package is specified by importPath. Examples found in _test.go files are associated with the corresponding type, function, method, or the package, based on their name. If the example has a suffix in its name, it is set in the Example.Suffix field. Examples with malformed names are skipped. Optionally, a single extra argument of type Mode can be provided to control low-level aspects of the documentation extraction behavior. NewFromFiles takes ownership of the AST files and may edit them, unless the PreserveAST Mode bit is on.
const PreserveAST Mode = 4 PreserveAST says to leave the AST unmodified. Originally, pieces of the AST such as function bodies were nil-ed out to save memory in godoc, but not all programs want that behavior.
func Synopsis(s string) string Synopsis returns a cleaned version of the first sentence in s. That sentence ends after the first period followed by space and not preceded by exactly one uppercase letter. The result string has no \n, \r, or \t characters and uses only single spaces between words. If s starts with any of the IllegalPrefixes, the result is the empty string.
func ToHTML(w io.Writer, text string, words map[string]string) ToHTML converts comment text to formatted HTML. The comment was prepared by DocReader, so it is known not to have leading, trailing blank lines nor to have trailing spaces at the end of lines. The comment markers have already been removed. Each span of unindented non-blank lines is converted into a single paragraph. There is one exception to the rule: a span that consists of a single line, is followed by another paragraph span, begins with a capital letter, and contains no punctuation other than parentheses and commas is formatted as a heading. A span of indented lines is converted into a <pre> block, with the common indent prefix removed. URLs in the comment text are converted into links; if the URL also appears in the words map, the link is taken from the map (if the corresponding map value is the empty string, the URL is not converted into a link). A pair of (consecutive) backticks (`) is converted to a unicode left quote (“), and a pair of (consecutive) single quotes (') is converted to a unicode right quote (”). Go identifiers that appear in the words map are italicized; if the corresponding map value is not the empty string, it is considered a URL and the word is converted into a link.
func ToText(w io.Writer, text string, indent, preIndent string, width int) ToText prepares comment text for presentation in textual output. It wraps paragraphs of text to width or fewer Unicode code points and then prefixes each line with the indent. In preformatted sections (such as program text), it prefixes each non-blank line with preIndent. A pair of (consecutive) backticks (`) is converted to a unicode left quote (“), and a pair of (consecutive) single quotes (') is converted to a unicode right quote (”).