如何查看特定 go 函数的文档?

rkr*_*rzr 5 vim go

我正在寻找一种便捷的方法来快速查找 Go 中不同函数和/或包的文档。我目前的方法是通过谷歌搜索 say ioutil.ReadFile,但这非常慢/不方便。理想的解决方案是直接在 vim 中工作,或者在 Go 解释器中工作(建议?)。

例如,在 Python 中,可以通过将鼠标悬停在函数上或使用 ipython 解释器(例如os.open?或 )在 PyDev 中显示函数的文档help(os.open)

您如何查看 Go 的具体文档?

zzz*_*zzz 5

你有很多可能性:

  • 浏览http://golang.org/pkg/和/或使用“搜索”框,它甚至知道正则表达式!
  • 运行本地 godoc 并为所有本地安装的软件包获取相同的结果。更快且离线!
  • 从命令行查询godoc:

$ 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)
  • 使用 Rob Pike 的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