如何搜索Go文档?

huangapple go评论83阅读模式
英文:

How to search Go documentation?

问题

文档很好,但有时很难找到特定的关键字。例如,搜索Next()会导致打开这个页面http://golang.org/search?q=next%28%29,但这并不是很有帮助。有没有更好的搜索文档的方法?

英文:

The documentation is great, but sometimes it is hard to find a specific keyword. For instance, searching for Next()results in this page http://golang.org/search?q=next%28%29 which is not very helpful. Is there a better way to search the documentation?

答案1

得分: 4

  • 不要在查询中包含括号。
  • 仅通过首字母的大写来搜索导出的标识符。

Next的搜索结果中,我认为结果集要好得多。

顺便说一句,旧的技术仍然非常强大 如何搜索Go文档?

jnml@fsc-r630:~/go/src/pkg$ egrep -nr '^func \([^)]+\) Next\(' *
archive/tar/reader.go:42:func (tr *Reader) Next() (*Header, error) {
bytes/buffer.go:273:func (b *Buffer) Next(n int) []byte {
container/ring/ring.go:26:func (r *Ring) Next() *Ring {
container/list/list.go:31:func (e *Element) Next() *Element {
database/sql/fakedb_test.go:658:func (rc *rowsCursor) Next(dest []driver.Value) error {
database/sql/sql.go:1300:func (rs *Rows) Next() bool {
debug/dwarf/entry.go:310:func (r *Reader) Next() (*Entry, error) {
net/smtp/auth.go:75:func (a *plainAuth) Next(fromServer []byte, more bool) ([]byte, error) {
net/smtp/auth.go:99:func (a *cramMD5Auth) Next(fromServer []byte, more bool) ([]byte, error) {
net/textproto/pipeline.go:36:func (p *Pipeline) Next() uint {
reflect/all_test.go:3390:func (x *exhaustive) Next() bool {
text/scanner/scanner.go:302:func (s *Scanner) Next() rune {
jnml@fsc-r630:~/go/src/pkg$
英文:
  • Do not include the parenthesis in the query.
  • Search only for exported identifiers by capitalization of the first letter.

Search for Next gains a much better result set IMO.

BTW, the old techiques are still going strong as well 如何搜索Go文档?

jnml@fsc-r630:~/go/src/pkg$ egrep -nr '^func \([^)]+\) Next\(' *
archive/tar/reader.go:42:func (tr *Reader) Next() (*Header, error) {
bytes/buffer.go:273:func (b *Buffer) Next(n int) []byte {
container/ring/ring.go:26:func (r *Ring) Next() *Ring {
container/list/list.go:31:func (e *Element) Next() *Element {
database/sql/fakedb_test.go:658:func (rc *rowsCursor) Next(dest []driver.Value) error {
database/sql/sql.go:1300:func (rs *Rows) Next() bool {
debug/dwarf/entry.go:310:func (r *Reader) Next() (*Entry, error) {
net/smtp/auth.go:75:func (a *plainAuth) Next(fromServer []byte, more bool) ([]byte, error) {
net/smtp/auth.go:99:func (a *cramMD5Auth) Next(fromServer []byte, more bool) ([]byte, error) {
net/textproto/pipeline.go:36:func (p *Pipeline) Next() uint {
reflect/all_test.go:3390:func (x *exhaustive) Next() bool {
text/scanner/scanner.go:302:func (s *Scanner) Next() rune {
jnml@fsc-r630:~/go/src/pkg$ 

答案2

得分: 4

Rob Pike写了一个完美的工具来实现这个。使用go安装它:

go get code.google.com/p/rspace.cmd/doc

然后你可以输入doc next(或者doc Next)来获取所有包中Next函数的一个很棒的列表,包括它们的文档和签名。如果你知道包的名称,你可以输入doc sql next或者doc sql.next。你甚至可以加上-url来获取该文档的在线URL,或者加上-src来获取该符号的实现文件名和行号。

你可以使用-pkg来访问包文档(出现在包页面顶部并且不属于任何项的文档):doc -pkg json

doc会搜索所有内容,你可以限制它只搜索函数、接口、变量等。不带参数运行它来获取文档。

这是一个非常棒的工具。在你使用Go语言编写代码时要保持它的近在咫尺。

英文:

Rob Pike wrote the perfect tool for this. Install it with go:

go get code.google.com/p/rspace.cmd/doc

You can then say doc next (or doc Next) and get an awesome list of Next functions in all packages, along with their documentations and signature. If you know the name of the package, you can say doc sql next or doc sql.next. You can even pass -url to get URL of that documentation online, or -src to get file name and line number for the implementation of that symbol.

You can access package documentation (documentation that appears at the top of a package’s page and doesn’t belong to any of its items) with -pkg: doc -pkg json.

doc searches for everything and you can limit it to only search for functions, interfaces, variables, etc. Run it without arguments to get the docs.

It’s such a great tool. Keep it close when you’re writing in Go.

答案3

得分: 2

这个工作得很好:

func ([(][^)]+[)] )?[N]ext

如果你想要不区分大小写的搜索,使用

func ([(][^)]+[)] )?next
英文:

This works pretty well:

func ([(][^)]+[)] )?[N]ext

If you want case-insensitive search, use

func ([(][^)]+[)] )?next

huangapple
  • 本文由 发表于 2013年7月13日 18:06:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/17629166.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定