➜ hello go help doc
usage: go doc [-u][-c][package|[package.]symbol[.method]]Doc prints the documentation comments associated with the item identified by its
arguments (a package, const, func, type, var, or method) followed by a one-line
summary of each of the first-level items "under" that item (package-level
declarations for a package, methods for a type, etc.).
Flags:
-c
Respect case when matching symbols.
-cmd
Treat a command(package main) like a regular package.
Otherwise package main's exported symbols are hidden
when showing the package's top-level documentation.
-u
Show documentation for unexported as well as exported
symbols and methods.
➜ lib go doc json.Decoder
package json // import "encoding/json"type Decoder struct { // Has unexported fields.
} A Decoder reads and decodes JSON values from an input stream.
func NewDecoder(r io.Reader) *Decoder
func (dec *Decoder) Buffered() io.Reader
func (dec *Decoder) Decode(v interface{}) error
func (dec *Decoder) More() bool
func (dec *Decoder) Token()(Token, error)func (dec *Decoder) UseNumber()
现在我们看到这个Decoder有很多方法,进一步查看这些方法的文档,比如Decode。
1
2
3
4
5
6
7
➜ lib go doc json.Decoder.Decode
func (dec *Decoder) Decode(v interface{}) error
Decode reads the next JSON-encoded value from its input and stores it in the
value pointed to by v.
See the documentation for Unmarshal for details about the conversion of JSON
into a Go value.
go doc使用就是这样,一步步,缩小范围,查看想看的那些包、结构体、接口或者函数方法的文档。
在线浏览文档
go doc终端查看的方式,虽然也很便捷,不过效率不高,并且没有查看细节以及进行跳转,为此Go为我们提供了基于浏览器使用的网页方式进行浏览API 文档,我们只用点点鼠标,就可以查看了,还可以在方法、包等之间进行跳转,更简洁方便。