doc
3 分钟阅读
doc
https://pkg.go.dev/go/doc@go1.20.1
Package doc extracts source code documentation from a Go AST.
常量
This section is empty.
变量
|
|
IllegalPrefixes is a list of lower-case prefixes that identify a comment as not being a doc comment. This helps to avoid misinterpreting the common mistake of a copyright notice immediately before a package statement as being a doc comment.
函数
func IsPredeclared <- go1.8
|
|
IsPredeclared reports whether s is a predeclared identifier.
Example
|
|
Example
|
|
Example
|
|
类型
type Example
|
|
An Example represents an example function found in a test source file.
func Examples
|
|
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, fuzz test, or benchmark function, and at least one top-level function, type, variable, or constant declaration other than the example function.
type Filter
|
|
type Func
|
|
Func is the documentation for a func declaration.
type Mode
|
|
Mode values control the operation of New and NewFromFiles.
|
|
type Note <- go1.1
|
|
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.
type Package
|
|
Package is the documentation for an entire package.
func New
|
|
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 <- go1.14
|
|
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.
Example
|
|
(*Package) Filter
|
|
Filter eliminates documentation for names that don’t pass through the filter f. TODO(gri): Recognize “Type.Method” as a name.
(*Package) HTML <- go1.19
|
|
HTML returns formatted HTML for the doc comment text.
To customize details of the HTML, use Package.Printer to obtain a comment.Printer, and configure it before calling its HTML method.
(*Package) Markdown <- go1.19
|
|
Markdown returns formatted Markdown for the doc comment text.
To customize details of the Markdown, use Package.Printer to obtain a comment.Printer, and configure it before calling its Markdown method.
(*Package) Parser <- go1.19
|
|
Parser returns a doc comment parser configured for parsing doc comments from package p. Each call returns a new parser, so that the caller may customize it before use.
(*Package) Printer <- go1.19
|
|
Printer returns a doc comment printer configured for printing doc comments from package p. Each call returns a new printer, so that the caller may customize it before use.
(*Package) Synopsis <- go1.19
|
|
Synopsis returns a cleaned version of the first sentence in text. That sentence ends after the first period followed by space and not preceded by exactly one uppercase letter, or at the first paragraph break. The result string has no \n, \r, or \t characters and uses only single spaces between words. If text starts with any of the IllegalPrefixes, the result is the empty string.
(*Package) Text <- go1.19
|
|
Text returns formatted text for the doc comment text, wrapped to 80 Unicode code points and using tabs for code block indentation.
To customize details of the formatting, use Package.Printer to obtain a comment.Printer, and configure it before calling its Text method.
type Type
|
|
Type is the documentation for a type declaration.
type Value
|
|
Value is the documentation for a (possibly grouped) var or const declaration.