How can I generate HTML documents using `godoc`?

后端 未结 4 502
一生所求
一生所求 2021-01-31 01:53

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 achiev

相关标签:
4条回答
  • 2021-01-31 02:17

    A simple HTML documentation can be produced by, for example:

    $ godoc -html container/heap Interface > page.html
    

    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.

    0 讨论(0)
  • 2021-01-31 02:21

    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

    0 讨论(0)
  • 2021-01-31 02:25

    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
    
    0 讨论(0)
  • 2021-01-31 02:27

    (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.

    0 讨论(0)
提交回复
热议问题