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:
go doc -cmd(note the difference between
go doc). This will treat
package mainlike a regular package. The drawback is that
go docdoes not offer a web interface.
- Split your command into two packages. Generally
mainwould 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.
godocand make it do what you want.
Refer to Reply #4 at http://stackoverflow.com/questions/21778556/can-i-document-package-main-in-godoc
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.