我正在尋找一種方便的方法來快速查找Go中不同功能和/或軟件包的文檔。我目前的做法是谷歌說ioutil.ReadFile
,但這是非常緩慢/不方便。 理想的解決方案可以直接在vim中或者在Go解釋器中使用(建議?)。如何查看特定go功能的文檔?
E.g.在Python中,函數的文檔可以在PyDev中通過懸停在函數上或使用ipython解釋器與例如os.open?
或help(os.open)
。
您如何查看Go的特定文檔?
我正在尋找一種方便的方法來快速查找Go中不同功能和/或軟件包的文檔。我目前的做法是谷歌說ioutil.ReadFile
,但這是非常緩慢/不方便。 理想的解決方案可以直接在vim中或者在Go解釋器中使用(建議?)。如何查看特定go功能的文檔?
E.g.在Python中,函數的文檔可以在PyDev中通過懸停在函數上或使用ipython解釋器與例如os.open?
或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.
$
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
可以使用用於該godoc命令行工具。 godoc os Open
將查找os.Open
並僅顯示與該功能相關的內容。您可以使用-ex
開啓示例。
例子:
$ godoc os Signal
PACKAGE DOCUMENTATION
package os
import "os"
TYPES
type File struct {
// contains filtered or unexported fields
}
File represents an open file descriptor.
func Open(name string) (file *File, err error)
Open opens the named file for reading. If successful, methods on the
returned file can be used for reading; the associated file descriptor
has mode O_RDONLY. If there is an error, it will be of type *PathError.
您還可以運行godoc -http
,它會運行一個Web服務器顯示您(在端口6060默認值)爲所有的軟件包的。
看看godoc documentation。這是一個偉大的工具,它可以做更多。
還有godoc.org,這基本上是一個替代godoc
Web前端自動生成,如果具備這樣的http://godoc.org/github.com/golang/groupcache#Context一展身手路徑第三方文檔去主持其他地方的代碼。
從Vim內部(假設您已安裝Go's plugin),輸入:Godoc <something>
,您將在不離開編輯器的情況下獲得文檔。你可以明顯地將一個鍵映射到這個(沒有參數,如果我沒記錯的話,它會在光標位置搜索該標記)。
也就是說,我經常用Rob Pike's doc
來代替,也來自Vim內部(:!doc <something>
)。
我沒有在godoc文檔中看到-ex標誌(當我嘗試它時它不起作用)。我將如何/在哪裏使用它? – rkrzr