Godoc does not document functions and variables in package main

This makes godoc REALLY REALLY irritating and far far less useful. Why doesn’t this work? Is there any easy workaround?

The thinking behind this is that godoc is intended for the user of a package, not the package writer. Thus only exported identifiers are shown. Since package main cannot be imported, there are effectively no exported identifiers. Therefore only the package documentation is displayed.

Here are some potential solutions/workarounds:

  1. Use go doc -cmd (note the difference between godoc and go doc). This will treat package main like a regular package. The drawback is that go doc does not offer a web interface.
  2. Split your command into two packages. Generally main would handle loading configs, parsing flags, etc; and then pass that config to the core of the program in another package. This puts the bulk of the code in a regular package. An example of this is github.com/rakyll/hey.
  3. Fork godoc and make it do what you want.

Refer to Reply #4 at http://stackoverflow.com/questions/21778556/can-i-document-package-main-in-godoc

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.