使用`go doc`命令查看示例函数?

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

Viewing Example functions with `go doc` command?

问题

如果我通过https://pkg.go.dev在网页上查看一个包的文档,页面会包含Example测试函数。但是使用go doc -u -all命令查看一个包的输出结果中并不包含这些信息。是否有可能将这些信息包含进去?

英文:

If I view a package's documentation via the web at https://pkg.go.dev, the page includes Example test functions. The output of go doc -u -all for a package does not. Is it possible to have such information included?

答案1

得分: 2

使用go doc命令无法显示示例。

命令实现忽略了示例。

英文:

It is not possible to display examples using the go doc command.

The command implementation ignores examples.

答案2

得分: 1

Godoc示例是Go代码片段,显示为包文档,并通过将其作为测试运行来进行验证。用户可以通过访问包的godoc网页并点击相关的“运行”按钮来运行这些示例。

https://go.dev/blog/examples

英文:

Godoc examples are snippets of Go code that are displayed as package documentation and that are verified by running them as tests. They can also be run by a user visiting the godoc web page for the package and clicking the associated “Run” button

https://go.dev/blog/examples

答案3

得分: 0

我使用以下命令安装了godoc:

go install -v golang.org/x/tools/cmd/godoc@latest

如果你的示例函数命名正确,它们会显示给你。我认为你应该在测试中正确命名你的示例函数。

英文:

I installed godoc with:

go install -v golang.org/x/tools/cmd/godoc@latest

And examples (if correctly named) are shown for me. I think you should correctly name your example functions in tests.

huangapple
  • 本文由 发表于 2022年9月11日 01:01:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/73673666.html
匿名

发表评论

匿名网友

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

确定