go - 我如何跳转到我在godoc中浏览的结构或方法中字段类型的文档?

标签 go godoc

我仍在努力以一种易于理解的方式来表达问题,因此我将记录我在遇到我面临的问题时所遵循的步骤。

  1. 我正在查找 net/http 包中请求结构的文档。我通过 godoc net/http Request
  2. 执行此操作
  3. 现在浏览文档,Request 结构的第一个字段是 URL,它是 *url.URL 类型,我想查找其文档。
  4. 但是 godoc 没有透露它属于哪个导入路径的细节。我只知道包名称本身是“url”,但它的规范导入路径类似于“some/path/url”,我想知道它以便我可以查找它并找出 URL 字段。<

要获取上述文档中引用的特定 url 包,我需要遵循哪些步骤?

最佳答案

Go 1.5

在 Go 1.5 中,您可以使用新的 go doc子命令:

Show documentation for package or symbol

Usage:

go doc [-u] [-c] [package|[package.]symbol[.method]]

Doc prints the documentation comments associated with the item identified by its arguments (a package, const, func, type, var, or method) followed by a one-line summary of each of the first-level items "under" that item (package-level declarations for a package, methods for a type, etc.).

[…]

When run with one argument, the argument is treated as a Go-syntax-like representation of the item to be documented. What the argument selects depends on what is installed in GOROOT and GOPATH, as well as the form of the argument, which is schematically one of these:

go doc <pkg>
go doc <sym>[.<method>]
go doc [<pkg>].<sym>[.<method>]

The first item in this list matched by the argument is the one whose documentation is printed. (See the examples below.) For packages, the order of scanning is determined lexically, but the GOROOT tree is always scanned before GOPATH.

因此,对于您的示例,只需go doc url.URL,您无需知道url 包作为net/url 导入。

Pre Go 1.5

在 Go 1.5 发布之前,有一个非常简单的命令可以安装:

go install robpike.io/cmd/doc

安装后,您将执行 doc url.URL

关于go - 我如何跳转到我在godoc中浏览的结构或方法中字段类型的文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31648354/

相关文章:

go - 如何只让go文档的一部分出现在godocs中

go - 运行 "go doc"导致 "no such tool"错误

Godoc,为整个包创建 html

json - 在 Golang Gorm 中隐藏字段

json - 如何使用脚本更改 Deployment 的 ConfigMap?

json - 使用Golang的示例JSON响应

go - 在 Go 中通过 Godoc 记录私有(private)结构上的公共(public)方法

http - 如何在POST请求中获取参数

go - 在Go中将文件从本地文件夹移动到s3存储桶