godoc (golang.org/x/tools/cmd/godoc) has become module-aware

1,103 views
Skip to first unread message

Dmitri Shuralyov

unread,
Nov 8, 2019, 1:52:07 PM11/8/19
to golan...@googlegroups.com
Hello gophers,

godoc, the local web server that displays documentation for Go packages (not to be confused with https://godoc.org, the website), has been updated with support for Go modules. (This was issue 33655.)

Module-aware mode is enabled whenever it would be enabled for the go command. That is, module mode is enabled when a go.mod file is found in, or in a parent of, the directory where you run the godoc command. Documentation is displayed for packages in the build list, which includes the main module and its dependencies. Environment variables such as GO111MODULEGOPRIVATE, GOPROXY that control the behavior of the go command also affect godoc.

As a reminder, the godoc command is no longer included in the binary distribution as of Go 1.13. You can install the latest version from its source at golang.org/x/tools/cmd/godoc.

If you run into unexpected problems, please let us know by leaving a comment on issue 33655, filing a new issue, or replying to this thread.

Thanks,
Dmitri

Ain

unread,
Nov 8, 2019, 2:55:53 PM11/8/19
to golang-nuts


On Friday, November 8, 2019 at 8:52:07 PM UTC+2, Dmitri Shuralyov wrote:
Hello gophers,

godoc, the local web server that displays documentation for Go packages (not to be confused with https://godoc.org, the website), has been updated with support for Go modules. (This was issue 33655.)

Great news, thank you!

Ain

marc...@gmail.com

unread,
Nov 8, 2019, 9:06:23 PM11/8/19
to golang-nuts
It would have been nice, if there were installation instructions on the page are redirected to when you click that link, so people know how to get a newer version.


Nelo Mitranim

unread,
Apr 9, 2020, 9:25:39 AM4/9/20
to golang-nuts
Trying and failing to use this. Help would be appreciated.

I'm working on a library module outside of GOPATH. The `go.mod` file is present. The `go` commands such as `go test` seem to run in module mode. But when I run `godoc -http=:6060`, it shows the standard library + packages from GOPATH, failing to include the current module. I've updated `godoc` via:

go get -u golang.org/x/tools/cmd/godoc

However I'm unable to check the installed `godoc` version, as it lacks such a subcommand, so I can't be sure if the installed version actually includes module support. The documentation doesn't give examples or mention modules at all. Any suggestions?

Hein Meling

unread,
Apr 11, 2020, 11:50:29 AM4/11/20
to golang-nuts
Maybe the godoc command got installed in your $HOME/go/bin folder and this folder is not in your $PATH?

Nelo Mitranim

unread,
Apr 13, 2020, 8:43:02 AM4/13/20
to golang-nuts
@Hein Meling Thanks for the pointer, this actually helped. It gets installed into `$GOPATH/bin`, which actually IS in my `$PATH`, but `which godoc` shows `/usr/local/bin/godoc`. My `.profile` explicitly puts `$GOPATH/bin` first, but somehow my $PATH starts with all sorts of crap like `/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:`. It never occurred to me to check. Thanks for the suggestion! I'm off to figure out what's causing this...

Meanwhile, `$GOPATH/bin/godoc` works as expected and even announces running in module mode. The documentation of the local module is present on the webpage. 👍 Thanks!
Reply all
Reply to author
Forward
0 new messages