我正在寻找一种方便的方法来快速查找 Go 中不同函数和/或包的文档。我目前的方法是用谷歌搜索 ioutil.ReadFile
,但这很慢/很不方便。
理想的解决方案将直接在 vim 中工作,或者可能在 Go 解释器中工作(建议?)。
例如在 Python 中,函数的文档可以通过将鼠标悬停在函数上或使用 ipython 解释器在 PyDev 中显示,例如os.open?
或 help(os.open)
。
您如何查看 Go 的特定文档?
最佳答案
你有很多可能性:
- 浏览 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.
$
- 使用 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)
$
[0]: $ go get code.google.com/p/rspace.cmd/doc
关于vim - 如何查看特定 go 函数的文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17945068/