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
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
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 (”).
 |
The pages are generated with Golds v0.1.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project and developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |