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:
- Use
go doc -cmd(note the difference betweengodocandgo doc). This will treatpackage mainlike a regular package. The drawback is thatgo 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. - Fork
godocand make it do what you want.
2 Likes
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.