What steps are needed to document `package main` in Godoc?

有些话、适合烂在心里 提交于 2019-12-02 20:53:11
ema

You need to build a slightly modified version of godoc to document main packages.

Please see https://github.com/golang/go/issues/5727.

tl;dr:

  1. Modify the following line in $GOPATH/src/golang.org/x/tools/godoc/server.go

    - info.IsMain = pkgname == "main"
    + info.IsMain = false && pkgname == "main"
    
  2. Build and install with go install golang.org/x/tools/cmd/godoc.

$GOPATH/bin/godoc should now behave as you wish.

AFAIK, you already have the answer to your question. I can think of two alternative solutions:

  1. Maintain a fork of godoc that shows functions for main packages. (And you'd then have to run an instance of it yourself on a web server. The downside is that people going straight to godoc.org for your package documentation will miss out.)
  2. Separate your main packages into sub-packages such that the main package is small or minimal. Documentation could then be read in those sub-packages. But as far as I know, this is not in widespread practice.

I think in general, godoc is for package documentation. Documentation for main packages is really only useful to people editing the source code of that package---so the documentation conceivably doesn't need to be publicized. On the other hand, this lacks the nice presentation/organization of godoc.

As a compromise, if you really want to publicize the documentation, I'd recommend an overview of the architecture of your program rather than a play-by-play of each function.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!