What steps are needed to document `package main` in Godoc?

后端 未结 2 1172
悲&欢浪女
悲&欢浪女 2021-02-02 17:59

Godoc is a great tool for documenting packages, however it seems to be less useful when it\'s used against package main. I\'ll see an output that only displays the

2条回答
  •  情深已故
    2021-02-02 18:09

    You need to build a slightly modified version of godoc to document main packages.

    Please see https://github.com/golang/go/issues/5727.

    tl;dr:

    1. Modify the following line in $GOPATH/src/golang.org/x/tools/godoc/server.go

      - info.IsMain = pkgname == "main"
      + info.IsMain = false && pkgname == "main"
      
    2. Build and install with go install golang.org/x/tools/cmd/godoc.

    $GOPATH/bin/godoc should now behave as you wish.

提交回复
热议问题