Liam Kelly
Liam Kelly

Reputation: 3714

How to run pkg.go.dev locally as a godoc replacement?

godoc has been removed from the go standard install since 1.12 and looks like it wont be updated anytime soon. pkg.go.dev at least appears to be its successor. It also has additional documentation features like grabbing the README.md file and rendering it in the documentation page.

For these reasons I was hoping to switch over to using pkg.go.dev locally to view and create documentation for small internal packages. The major issue is that unlike godoc there does not seem to be a clear usage guide. I also do not know if pkpg.go.dev is completely overkill for this task. So I would like to know:

  1. Can and should pkg.go.dev be used as a local godoc replacement?
  2. If yes, how would I run it for this task?

Upvotes: 5

Views: 2953

Answers (3)

invzhi
invzhi

Reputation: 136

Run pkgsite locally.

go install golang.org/x/pkgsite/cmd/pkgsite@latest && pkgsite

References:

  1. https://tip.golang.org/doc/comment
  2. https://pkg.go.dev/golang.org/x/pkgsite/cmd/pkgsite

Upvotes: 11

Zombo
Zombo

Reputation: 1

Running godoc [1] on its own worked for me, but was really slow because it generates docs for every single package in the standard library, while I only care about the local package that I am working on. To that end, if your package is in a folder called something, you can move the folder so that it looks like this:

godoc/src/something

Then, go to the godoc folder, and run

godoc -goroot .

Then, browse to localhost:6060. Alternatively, another site is available for Go docs [2].

  1. https://github.com/golang/tools/tree/master/cmd/godoc
  2. https://godocs.io

Upvotes: 0

NuLo
NuLo

Reputation: 1528

You can use the x/tools/godoc that has the previous godoc tool

Upvotes: 0

Related Questions