如何使用`godoc`生成HTML文档?

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

How can I generate HTML documents using `godoc`?

问题

我写了一个小的Go程序,我想从源代码生成独立的HTML文档,可以在没有godoc服务器的情况下查看。但是我找不到任何方法来实现它。如果有人能帮助我,我将非常感激。

英文:

I have written a small go program, and I want to generate standalone HTML documents from source code that can be viewed without godoc server. But I can't find any way to achieve it. if anyone could help me, I'll appreciate it.

答案1

得分: 48

一个稍微好一点的形式可以通过以下方式产生:

godoc -url "http://localhost:6060/pkg/container/heap/" > page.html 

(我正在运行godoc服务器在端口6060上,我不确定这是否是先决条件)。

如果将生成的HTML文件适当地引用原始CSS样式,那么HTML可能会看起来更好,这些样式可以在Go代码库中找到。

英文:

A bit better form can by produced by:

godoc -url "http://localhost:6060/pkg/container/heap/" > page.html 

(I have godoc server running at :6060 and I'm not sure if that's a prerequisite).

The HTML would probably look better if combined with original CSS styles found in the Go repository by adjusting the produced HTML files to properly refer to it.

答案2

得分: 18

这可能不是直接回答你的问题,但如果你计划开源你的项目,你不需要手动生成HTML。只需确保你的源代码中有适当插入的注释,并使用godoc.org(http://godoc.org/-/about)来处理它。

它可以显示Bitbucket、Github、Launchpad和Google Project Hosting上的Go包的文档。

例如,可以查看这个链接:http://godoc.org/code.google.com/p/go.crypto/ssh

英文:

This might not directly answer your question, but if you are planning to open source your project, you don't really have to generate HTML manually. Just make sure you have comments properly inserted in your source code, and use godoc.org( http://godoc.org/-/about ) to handle it.

It displays documentation for Go packages on Bitbucket, Github, Launchpad and Google Project Hosting.

Check this out for example: http://godoc.org/code.google.com/p/go.crypto/ssh

答案3

得分: 9

运行服务器并使用wget获取它

godoc -http=:6060

等待它启动后(使用您的应用程序的“container/heap/”):

wget -p -k http://localhost:6060/pkg/container/heap/

要下载所有文档,我使用以下命令:

wget -m -k -q -erobots=off --no-host-directories --no-use-server-timestamps http://localhost:6060
英文:

Run the server and get it with wget

godoc -http=:6060

wait for it to start up then ("container/heap/" with your app):

wget -p -k http://localhost:6060/pkg/container/heap/

To download all docs I use following:

wget -m -k -q -erobots=off --no-host-directories --no-use-server-timestamps http://localhost:6060

答案4

得分: 0

如果您想尝试不同的文档样式,可以尝试Golds,这是一个备选的Go文档生成工具(以及本地文档服务器/代码阅读器)。

在您的项目目录下,您可以运行以下任何命令来为您的Go项目生成HTML文档:

  • golds -gen -nouses -plainsrc -wdpkgs-listing=promoted ./...
  • golds -gen -nouses -wdpkgs-listing=promoted ./...
  • golds -gen -wdpkgs-listing=promoted ./...

第一个命令生成最紧凑的文档,最后一个命令生成完整的文档,其大小是紧凑文档的6倍。

顺便说一下,我是Golds的作者。希望这个工具能满足您的需求。

英文:

(Moved from https://stackoverflow.com/a/63905155/3715832)

If you would like to try a different docs style, you can try Golds, which is an alternate Go docs generation tool (and a local docs server / code reader).

Under your project directory, you can run any of the following commands to generate HTML docs for your Go project:

  • golds -gen -nouses -plainsrc -wdpkgs-listing=promoted ./...
  • golds -gen -nouses -wdpkgs-listing=promoted ./...
  • golds -gen -wdpkgs-listing=promoted ./...

The first command generates the most compact docs and the last one generates the full docs, which size is 6 times of the compact docs.

BTW, I'm the author of Golds. Hope you this tool would satisfy your need.

huangapple
  • 本文由 发表于 2012年11月23日 21:28:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/13530120.html
匿名

发表评论

匿名网友

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

确定