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

huangapple go评论75阅读模式
英文:

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

问题

godoc已经从Go标准安装中移除自1.12版本,而且看起来它不会很快得到更新。pkg.go.dev至少看起来是它的继任者。它还具有其他文档功能,比如获取README.md文件并在文档页面中呈现。

出于这些原因,我希望切换到在本地使用pkg.go.dev来查看和创建小型内部包的文档。主要问题是,与godoc不同,似乎没有明确的使用指南。我也不知道pkg.go.dev是否完全适合这个任务。所以我想知道:

  1. 是否可以并且应该将pkg.go.dev用作本地的godoc替代品?
  2. 如果是,我应该如何运行它来完成这个任务?
英文:

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?

答案1

得分: 2

运行本地 pkgsite。

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

参考资料:

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

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

答案2

得分: 0

你可以使用x/tools/godoc来使用之前的godoc工具。

英文:

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

答案3

得分: 0

运行godoc 1本身对我来说是可行的,但是非常慢,因为它会为标准库中的每个包生成文档,而我只关心我正在使用的本地包。为此,如果您的包在名为something的文件夹中,您可以将该文件夹移动,使其看起来像这样:

godoc/src/something

然后,进入godoc文件夹,运行

godoc -goroot .

然后,浏览到localhost:6060。或者,还有另一个用于Go文档的网站 2

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

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

huangapple
  • 本文由 发表于 2021年10月25日 21:42:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/69709122.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定