目录 搜索
archive archive/tar archive/zip bufio bufio(缓存) builtin builtin(内置包) bytes bytes(包字节) compress compress/bzip2(压缩/bzip2) compress/flate(压缩/flate) compress/gzip(压缩/gzip) compress/lzw(压缩/lzw) compress/zlib(压缩/zlib) container container/heap(容器数据结构heap) container/list(容器数据结构list) container/ring(容器数据结构ring) context context(上下文) crypto crypto(加密) crypto/aes(加密/aes) crypto/cipher(加密/cipher) crypto/des(加密/des) crypto/dsa(加密/dsa) crypto/ecdsa(加密/ecdsa) crypto/elliptic(加密/elliptic) crypto/hmac(加密/hmac) crypto/md5(加密/md5) crypto/rand(加密/rand) crypto/rc4(加密/rc4) crypto/rsa(加密/rsa) crypto/sha1(加密/sha1) crypto/sha256(加密/sha256) crypto/sha512(加密/sha512) crypto/subtle(加密/subtle) crypto/tls(加密/tls) crypto/x509(加密/x509) crypto/x509/pkix(加密/x509/pkix) database database/sql(数据库/sql) database/sql/driver(数据库/sql/driver) debug debug/dwarf(调试/dwarf) debug/elf(调试/elf) debug/gosym(调试/gosym) debug/macho(调试/macho) debug/pe(调试/pe) debug/plan9obj(调试/plan9obj) encoding encoding(编码) encoding/ascii85(编码/ascii85) encoding/asn1(编码/asn1) encoding/base32(编码/base32) encoding/base64(编码/base64) encoding/binary(编码/binary) encoding/csv(编码/csv) encoding/gob(编码/gob) encoding/hex(编码/hex) encoding/json(编码/json) encoding/pem(编码/pem) encoding/xml(编码/xml) errors errors(错误) expvar expvar flag flag(命令行参数解析flag包) fmt fmt go go/ast(抽象语法树) go/build go/constant(常量) go/doc(文档) go/format(格式) go/importer go/parser go/printer go/scanner(扫描仪) go/token(令牌) go/types(类型) hash hash(散列) hash/adler32 hash/crc32 hash/crc64 hash/fnv html html html/template(模板) image image(图像) image/color(颜色) image/color/palette(调色板) image/draw(绘图) image/gif image/jpeg image/png index index/suffixarray io io io/ioutil log log log/syslog(日志系统) math math math/big math/big math/bits math/bits math/cmplx math/cmplx math/rand math/rand mime mime mime/multipart(多部分) mime/quotedprintable net net net/http net/http net/http/cgi net/http/cookiejar net/http/fcgi net/http/httptest net/http/httptrace net/http/httputil net/http/internal net/http/pprof net/mail net/mail net/rpc net/rpc net/rpc/jsonrpc net/smtp net/smtp net/textproto net/textproto net/url net/url os os os/exec os/signal os/user path path path/filepath(文件路径) plugin plugin(插件) reflect reflect(反射) regexp regexp(正则表达式) regexp/syntax runtime runtime(运行时) runtime/debug(调试) runtime/internal/sys runtime/pprof runtime/race(竞争) runtime/trace(执行追踪器) sort sort(排序算法) strconv strconv(转换) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系统调用) testing testing(测试) testing/iotest testing/quick text text/scanner(扫描文本) text/tabwriter text/template(定义模板) text/template/parse time time(时间戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
文字

  • import "go/doc"

  • Overview

  • Index

概观

Package doc从Go AST中提取源代码文档。

索引

  • Variables

  • func Examples(files ...*ast.File) []*Example

  • func IsPredeclared(s string) bool

  • func Synopsis(s string) string

  • func ToHTML(w io.Writer, text string, words map[string]string)

  • func ToText(w io.Writer, text string, indent, preIndent string, width int)

  • type Example

  • type Filter

  • type Func

  • type Mode

  • type Note

  • type Package

  • func New(pkg *ast.Package, importPath string, mode Mode) *Package

  • func (p *Package) Filter(f Filter)

  • type Type

  • type Value

包文件

comment.go doc.go example.go exports.go filter.go reader.go synopsis.go

变量

var IllegalPrefixes = []string{        "copyright",        "all rights",        "author",}

func Examples

func Examples(files ...*ast.File) []*Example

Examples返回按名称字段排序的文件中找到的示例。Order字段记录遇到示例的顺序。

可播放的示例必须位于名称以“_test”结尾的包中。在以下任一情况下,示例都是“可播放的”(播放字段不为零):

- 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

func IsPredeclared(s string) bool

IsPredeclared报告s是否是预先标识的标识符。

func Synopsis

func Synopsis(s string) string

Synopsis返回s中第一句话的清晰版本。该句在第一个句点后加空格,并且前面没有一个大写字母后结束。结果字符串没有\ n,\ r或\ t字符,并且在单词之间只使用单个空格。如果s从任何非法前缀开始,则结果是空字符串。

func ToHTML

func ToHTML(w io.Writer, text string, words map[string]string)

ToHTML将注释文本转换为格式化的HTML。该评论是由DocReader编写的,因此已知不会在行尾有空行,也不会在行尾有尾随空格。评论标记已被删除。

不缩进的非空行的每个跨度都被转换为单个段落。规则有一个例外:由单一行组成的跨度,后面跟着另一段跨度,以大写字母开头,并且不包含标点符号被格式化为标题。

缩进行的跨度被转换为<pre>块,并删除了公共缩进前缀。

评论文本中的URL被转换为链接; 如果URL也出现在单词映射中,则链接将从映射中获取(如果相应的映射值是空字符串,则URL不会转换为链接)。

出现在单词映射中的Go标识符以斜体表示; 如果相应的映射值不是空字符串,则将其视为URL并将该单词转换为链接。

func ToText

func ToText(w io.Writer, text string, indent, preIndent string, width int)

ToText以文本输出的形式准备评论文本。它将文本段落包装成宽度或更少的Unicode代码点,然后将每行缩进前缀。在预先格式化的部分(如程序文本)中,它使用preIndent前缀每个非空行。

type Example

一个Example 代表了一个在源文件中找到的示例函数。

type Example struct {
        Name        string // name of the item being exemplified
        Doc         string // example function doc string
        Code        ast.Node
        Play        *ast.File // a whole program version of the example
        Comments    []*ast.CommentGroup
        Output      string // expected output
        Unordered   bool
        EmptyOutput bool // expect empty output
        Order       int  // original source code order}

type Filter

type Filter func(string) bool

type Func

Func是func声明的文档。

type Func struct {
        Doc  string
        Name string
        Decl *ast.FuncDecl        // methods        // (for functions, these fields have the respective zero value)
        Recv  string // actual   receiver "T" or "*T"
        Orig  string // original receiver "T" or "*T"
        Level int    // embedding level; 0 means not embedded}

type Mode

Mode值控制New的操作。

type Mode int
const (        // extract documentation for all package-level declarations,        // not just exported ones
        AllDecls Mode = 1 << iota        // show all embedded methods, not just the ones of        // invisible (unexported) anonymous fields
        AllMethods)

type Note

Note 代表以“MARKER(uid):note body”开头的标注注释。任何带有2个或更多大写AZ字母的标记以及至少一个字符的uid都被识别。uid后面的“:”是可选的。注释收集在由Note 标记索引的Package.Notes地图中。

type Note struct {
        Pos, End token.Pos // position range of the comment containing the marker
        UID      string    // uid found with the marker
        Body     string    // note body text}

type Package

Package 是整个包的文档。

type Package struct {
        Doc        string
        Name       string
        ImportPath string
        Imports    []string
        Filenames  []string
        Notes      map[string][]*Note        // Deprecated: For backward compatibility Bugs is still populated,        // but all new code should use Notes instead.
        Bugs []string        // declarations
        Consts []*Value
        Types  []*Type
        Vars   []*Value
        Funcs  []*Func}

func New

func New(pkg *ast.Package, importPath string, mode Mode) *Package

New计算给定包AST的包文档。New取得AST pkg的所有权,并可以编辑或覆盖它。

func (*Package) Filter

func (p *Package) Filter(f Filter)

过滤器消除了不通过过滤器f的名称的文档。TODO(gri):将“Type.Method”识别为名称。

type Type

Type是类型声明的文档。

type Type struct {
        Doc  string
        Name string
        Decl *ast.GenDecl        // associated declarations
        Consts  []*Value // sorted list of constants of (mostly) this type
        Vars    []*Value // sorted list of variables of (mostly) this type
        Funcs   []*Func  // sorted list of functions returning this type
        Methods []*Func  // sorted list of methods (including embedded ones) of this type}

type Value

Value 是(可能分组的)var或const声明的文档。

type Value struct {
        Doc   string
        Names []string // var or const names in declaration order
        Decl  *ast.GenDecl        // contains filtered or unexported fields}
上一篇: 下一篇: