我正在寻找一种便捷的方法来快速查找 Go 中不同函数和/或包的文档。我目前的方法是通过谷歌搜索 say ioutil.ReadFile,但这非常慢/不方便。理想的解决方案是直接在 vim 中工作,或者在 Go 解释器中工作(建议?)。
例如,在 Python 中,可以通过将鼠标悬停在函数上或使用 ipython 解释器(例如os.open?或 )在 PyDev 中显示函数的文档help(os.open)。
您如何查看 Go 的具体文档?
你有很多可能性:
$ godoc io/ioutil ReadFile
PACKAGE DOCUMENTATION
package ioutil
import "io/ioutil"
FUNCTIONS
func ReadFile(filename string) ([]byte, error)
ReadFile reads the file named by filename and returns the contents. A
successful call returns err == nil, not err == EOF. Because ReadFile
reads the whole file, it does not treat an EOF from Read as an error to
be reported.
$
Run Code Online (Sandbox Code Playgroud)
doc[0]。$ doc ioutil.ReadFile
http://golang.org/pkg/io/ioutil/#ReadFile
/home/jnml/go/src/pkg/io/ioutil/ioutil.go:48:
// ReadFile reads the file named by filename and returns the contents.
// A successful call returns err == nil, not err == EOF. Because ReadFile
// reads the whole file, it does not treat an EOF from Read as an error
// to be reported.
func ReadFile(filename string) ([]byte, error)
$
Run Code Online (Sandbox Code Playgroud)
[0]:$ go get code.google.com/p/rspace.cmd/doc