在Godoc中需要什么步骤来记录`package main`? [英] What steps are needed to document `package main` in Godoc?
问题描述
Godoc是一个很好的文档包工具,但是当它与 package main
一起使用时,它似乎没什么用。我将看到一个输出,仅显示使用 // BUG
和子目录写给自己的笔记。
Godoc is a great tool for documenting packages, however it seems to be less useful when it's used against package main
. I'll see an output that only displays the notes I've written to myself using //BUG
and subdirectories.
Godoc仅显示导出的功能,似乎无法显示main中的未导出的功能。我会发现查看main函数列表很有用。由于不支持此功能,因此我倾向于在软件包说明的顶部插入一个功能列表,但这感觉像是一种解决方法。
Godoc only displays exported functions and seems to have no way to display unexported / functions from main. I would find it useful to see a list of functions in main. Since this isn't supported, I tend to shove a list of functions at the top of the package description but this feels like a workaround.
因为我必须手动更新在函数列表中,我经常在程序包中放入尽可能多的代码,以便将其导出并记录下来。这是一个好主意吗?我应该如何处理main函数列表?
Since I have to manually update the list of functions, I often put as much code in packages as I can so it's exported and thus documented. Is this a good idea? What should I do about the list of functions in main?
示例:
COMMAND DOCUMENTATION
Package main implements a web server, template renderer and DAL for MySQL.
<filename.go>
<function>(<signature>)
main.go
main()
bootstrap() error
<more functions here>
BUGS
[filename.go] <whatever...>
SUBDIRECTORIES
auth
common
debug
storage
<more packages here>
推荐答案
您需要构建<$的稍微修改的版本c $ c> godoc 来记录主软件包。
You need to build a slightly modified version of godoc
to document main packages.
请参阅 https://github.com/golang/go/issues/5727 。
tl; dr :
-
在
$ GOPATH / src / golang.org / x / tools /中修改以下行godoc / server.go
- info.IsMain = pkgname == "main"
+ info.IsMain = false && pkgname == "main"
使用 go编译并安装golang.org/x/tools/cmd/godoc
。
$ GOPATH / bin / godoc
现在应该可以按照您的意愿运行。
$GOPATH/bin/godoc
should now behave as you wish.
这篇关于在Godoc中需要什么步骤来记录`package main`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!