DEV Community


Posted on

Show comments in GoDoc


GoDoc show comments in code when runs godoc command with notes option. The notes option can specify regular expression matching note markers to show(default is BUG).

$ godoc --help
usage: godoc package [name ...] 
  -notes string
        regular expression matching note markers to show (default "BUG") 
package exter

type Exter struct {

func NewExter() {
    // TODO(who): implement
    return Exter{}

func (exter *Exter) Run() error {
    // BUG(who): Not return correct value
    return nil

For example, there is a code the above, doc shows as follows.


But if you remove (who) from comment, comment not shows in GoDoc.

This is because of the limit of GoDoc.

The notes need to write a comment as MARKER(uid): note body. Also, MAKER needs 2 or more uppercase [A-Z] letters and a UID of at least one character.

This is describing at Note type comment.

Regex for MARKER is here:

It is a little unusual for (uid) to be mandatory (at least for me ;) ), so be careful.

Top comments (1)

moisoto profile image
Moises Soto

Nice post. The problem now is that godoc is no longer a command line utility.
Is nice to be able to display TODOs and BUGs on the doc server but if you know a way to show this using go doc subcommand please let me know.