gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 03:37:33 25 4
gpt4 key购买 nike

我正在使用 godocs 来记录我用 go/golang 编写的 API,我正在使用 godocs 来记录它,因为我生成了整个 main.go 文件的 HTML 页面,其中包含用于创建我的 API 的所有函数。但是,我不想显示有关我的所有辅助函数的信息,我只想显示有关文件中某些函数的标题信息。有没有办法只允许文件中的某些函数成为文档的一部分,或者我是否必须为我的所有辅助函数创建另一个文件?现在我正在本地端口 8000 上测试它:godoc -http=:8000

最佳答案

命令 godoc 及其堂兄弟 go doc默认行为,显示导出声明的包文档 .奇怪的是,我没有找到一个简单的权威来源来链接到明确记录这一事实的链接,但有一些对改变默认行为的命令中引用的事实的推论,例如来自 godoc package's documentation 的命令。 :

The presentation mode of web pages served by godoc can be controlled with the "m" URL parameter; it accepts a comma-separated list of flag names as value:

...

For instance, http://golang.org/pkg/math/big/?m=all,text shows the documentation for all (not just the exported) declarations of package big, in textual form (as it would appear when using godoc from the command line: "godoc -src math/big .*").

源代码位于 https://golang.org/src/go/doc/doc.go其中包括:

81    const (
82 // extract documentation for all package-level declarations,
83 // not just exported ones
84 AllDecls Mode = 1 << iota
...
89 )

https://golang.org/src/go/doc/exports.go记录一个函数:

241    // fileExports removes unexported declarations from src in place.

最后在终端中运行 go doc -h 会显示一个标志:

-u 显示未导出的符号以及导出的符号。

关于go - 如何只让go文档的一部分出现在godocs中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37625351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com