godoc and go doc.
Primary documentation tools
godoc— historically provided an HTML view of package documentation and could run a local documentation server.go doc— the modern, included command-line tool that prints package and identifier documentation in the terminal.

- Documentation lives next to code, so it is more likely to be updated when implementation changes.
- Well-structured comments improve discoverability of package features via
go docand generated HTML pages. - Following canonical conventions produces clearer, more consistent output in generated docs.
Convention and best practices
- Place a comment directly before the declaration of a package, type, variable, constant, or function. Do not insert a blank line between the comment and the declaration.
- Use a blank comment line to separate paragraphs inside long comments.
- Package-level documentation is commonly placed in a file named
doc.goinside the package. - Comments for exported identifiers (those that start with an uppercase letter) should begin with the identifier name. For example, a comment for
Nimbusshould start with “Nimbus …”. This canonical convention yields nicer generated documentation.
go doc presents information
go doc decryptprints package-level documentation and a list of exported identifiers in the package.go doc decrypt Nimbusprints the documentation for theNimbusidentifier (its comment and signature).
Exported identifiers should have comments that start with the identifier name (for example, “Nimbus …”). This convention improves clarity and produces better generated documentation.
Do not insert a blank line between a declaration and its preceding comment. A blank line detaches the comment from the declaration and prevents tools like
go doc from associating the comment with the symbol.- At minimum, document all exported identifiers — this significantly helps users of your package.
- Keep comments concise and accurate; update them as the code evolves.
- Use
go docfor quick local inspection; usegodocor static site generators when you need an HTML view or a local documentation server. - Consider adding a
doc.gowith package overview, examples, and package-level details to improve discoverability.
- Go project documentation
- godoc source and usage notes
- The
go doccommand documentation - Effective Go: commenting