excluding Go standard library packages from godoc output

2,120 views
Skip to first unread message

Jiri Simsa

unread,
Mar 18, 2015, 6:01:15 PM3/18/15
to golan...@googlegroups.com, Todd Wang, Jason Campbell
Hello golang-dev,

Is there an option / mechanism to exclude the Go standard library packages (and "Other packages") from showing up in the godoc http server? The reason I ask is that we are trying to create a web site that serves documentation only for the Go packages of our Go project and ideally we would like to make use of godoc.

Best,

--
Jiří Šimša

Aram Hăvărneanu

unread,
Mar 18, 2015, 6:09:31 PM3/18/15
to Jiri Simsa, golang-dev, Todd Wang, Jason Campbell
GOROOT=/tmp go list all

--
Aram Hăvărneanu

Jiri Simsa

unread,
Mar 18, 2015, 8:12:28 PM3/18/15
to Aram Hăvărneanu, golang-dev, Todd Wang, Jason Campbell
That does not quite answer my question. I am talking about the godoc web server that can be started using:

godoc -http=:<port>

For example, the golang.org website is an instance of this web server.

--
Jiří Šimša

Aram Hăvărneanu

unread,
Mar 18, 2015, 8:16:11 PM3/18/15
to Jiri Simsa, golang-dev, Todd Wang, Jason Campbell
Did you try setting the variable? It works for godoc too. It works for
everything that uses go/build.

--
Aram Hăvărneanu

Andrew Gerrand

unread,
Mar 18, 2015, 8:16:27 PM3/18/15
to Jiri Simsa, Aram Hăvărneanu, golang-dev, Todd Wang, Jason Campbell
I think Aram is suggesting that you set GOROOT to somewhere other than a real go root, so that godoc won't find the standard packages.

--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aram Hăvărneanu

unread,
Mar 18, 2015, 8:17:18 PM3/18/15
to Andrew Gerrand, Jiri Simsa, golang-dev, Todd Wang, Jason Campbell
On Thu, Mar 19, 2015 at 1:15 AM, Andrew Gerrand <a...@golang.org> wrote:
> I think Aram is suggesting that you set GOROOT to somewhere other than a
> real go root, so that godoc won't find the standard packages.

Yes.

--
Aram Hăvărneanu

Dan Kortschak

unread,
Mar 18, 2015, 8:18:22 PM3/18/15
to Jiri Simsa, Aram Hăvărneanu, golang-dev
On Wed, 2015-03-18 at 17:12 -0700, 'Jiri Simsa' via golang-dev wrote:
> godoc -http=:<port>
>
> For example, the golang.org website is an instance of this web server.

GOROOT=/tmp godoc -http=:<port>


Jiri Simsa

unread,
Mar 18, 2015, 8:24:23 PM3/18/15
to Aram Hăvărneanu, Andrew Gerrand, golang-dev, Todd Wang, Jason Campbell
Yes, I have tried that. It does not work seamlessly as the godoc tool is expecting a "valid" GOROOT:

$ godoc -http=:6060 -goroot=/tmp
2015/03/18 17:18:17 updateMetadata: open /tmp/doc: no such file or directory
2015/03/18 17:18:17 updateMetadata: open /tmp/doc: no such file or directory
...

and the homepage of the godoc web server ends up displaying the contents of my /tmp directory in this case.


--
Jiří Šimša

Aram Hăvărneanu

unread,
Mar 18, 2015, 8:28:32 PM3/18/15
to Jiri Simsa, Andrew Gerrand, golang-dev, Todd Wang, Jason Campbell
Just go to /pkg, the top level site doesn't work, but package
documentation (and source code) works fine.

--
Aram Hăvărneanu

Jiri Simsa

unread,
Mar 18, 2015, 8:47:16 PM3/18/15
to Aram Hăvărneanu, Andrew Gerrand, golang-dev, Todd Wang, Jason Campbell
Thanks. I wonder what would be needed to fix up the top level site issue (and other such loose ends). My team is hoping to use godoc for hosting of project documentation and we need the solution to look presentable.

Another option we have considered is to use godoc.org, but AFAICT the site has no mechanism to limit searches to a particular package prefix, which is one of our requirements.

Jiří Šimša

Dave Cheney

unread,
Mar 18, 2015, 8:50:16 PM3/18/15
to Jiri Simsa, Aram Hăvărneanu, Andrew Gerrand, golang-dev, Todd Wang, Jason Campbell

Can you put nginx in front of godoc and redirect any request that doesn't match the prefix you want you the root of your prefix?


Caleb Spare

unread,
Mar 18, 2015, 9:00:41 PM3/18/15
to Jiri Simsa, Aram Hăvărneanu, Andrew Gerrand, golang-dev, Todd Wang, Jason Campbell
I think the godoc webserver could be improved for use cases that aren't running golang.org.

One thing I've done in the past is to generate static docs by crawling the site (see https://github.com/golang/go/issues/2381; eventually godoc might generate html directly) and then munging the html to my needs and presenting it in a different context (for an internal documentation site that included other generated documentation).

Andrew Gerrand

unread,
Mar 18, 2015, 9:13:48 PM3/18/15
to Caleb Spare, Jiri Simsa, Aram Hăvărneanu, golang-dev, Todd Wang, Jason Campbell
For sure, I think we can add an option to godoc to hide the stdlib, for example. 

Jiri Simsa

unread,
Mar 19, 2015, 12:50:42 PM3/19/15
to Andrew Gerrand, Caleb Spare, Aram Hăvărneanu, golang-dev, Todd Wang, Jason Campbell
That would be great. Andrew, do you have a good sense of how tightly is the golang.org content and style integrated into the godoc source code? I wonder if the two could be separated so that one could repurpose godoc simply by providing an alternative set of assets.

--
Jiří Šimša

Andrew Gerrand

unread,
Mar 19, 2015, 6:01:46 PM3/19/15
to Jiri Simsa, Caleb Spare, Aram Hăvărneanu, golang-dev, Todd Wang, Jason Campbell
It's not too hard. I don't have time to walk you through it right now, unfortunately (leaving for vacation at EOD). Take a look at the source.

minux

unread,
Mar 19, 2015, 6:49:20 PM3/19/15
to Jiri Simsa, Andrew Gerrand, Caleb Spare, Aram Hăvărneanu, golang-dev, Todd Wang, Jason Campbell
On Thu, Mar 19, 2015 at 12:50 PM, 'Jiri Simsa' via golang-dev <golan...@googlegroups.com> wrote:
That would be great. Andrew, do you have a good sense of how tightly is the golang.org content and style integrated into the godoc source code? I wonder if the two could be separated so that one could repurpose godoc simply by providing an alternative set of assets.

Basically the templates are in http://godoc.org/golang.org/x/tools/godoc/static, modify
those files and then run go generate, and rebuild godoc.

Manlio Perillo

unread,
Mar 20, 2015, 9:54:20 AM3/20/15
to golan...@googlegroups.com, to...@google.com, jasonc...@google.com, jsi...@google.com
Il giorno mercoledì 18 marzo 2015 23:01:15 UTC+1, Jiri Simsa ha scritto:
Hello golang-dev,

Is there an option / mechanism to exclude the Go standard library packages (and "Other packages") from showing up in the godoc http server? The reason I ask is that we are trying to create a web site that serves documentation only for the Go packages of our Go project and ideally we would like to make use of godoc.


I posted a similar issue on golang-nuts some time ago.
My problem was that when running godoc from a Go workspace, non standard packages are listed as they were standard packages.


Regards  Manlio 

Jiri Simsa

unread,
Mar 24, 2015, 9:06:39 PM3/24/15
to Manlio Perillo, golang-dev, Todd Wang, Jason Campbell
FYI, I was able to repurpose godoc to serve the documentation for my team's project by modifying the assets pointed out by minux (godoc.html and pacakge.html in particular) and providing a simple index.html in the fake goroot that redirects to the /pkg page.

Thanks for the help.

--
Jiří Šimša

Reply all
Reply to author
Forward
0 new messages