英文:
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网页并点击相关的“运行”按钮来运行这些示例。
英文:
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
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论